2

我有一个图表,其中日期(字符串)作为 X 值,小数作为 Y 值。我想放大图表,但设置时:

chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;

它在 X 轴上放大到间隔 1。我想在轴上逐渐放大,但是当我设置\

chart1.ChartAreas[0].CursorX.Interval = 0.1; 

(除 1 之外的任何内容)X 轴上的标签消失。有人可以帮我吗,我是图表控件的新手。请原谅我的无知。任何建议将不胜感激到目前为止,这是我的一段代码:

chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;

chart1.Series[0].IsVisibleInLegend = false;
chart1.Series[0].ChartType = SeriesChartType.Area;

DateTime sday = Convert.ToDateTime(earnings1.dataGridView1[0, 0].Value.ToString());
chart1.Series[0].XValueType = ChartValueType.String;
int i = 0;
chart1.Series[0].SmartLabelStyle.Enabled = false;

foreach (DataGridViewRow dgvr in earnings1.dataGridView1.Rows)
{
         decimal testing = Convert.ToDecimal(earnings1.dataGridView1[1, i].Value);
         testing = decimal.Truncate(testing);
         var point = new DataPoint(i + 1, Convert.ToDouble(testing));
         point.Label = testing.ToString();
         point.Font = new Font("Century Gothic", 8, FontStyle.Bold);
         chart1.Series[0].Points.Add(point);
         chart1.Series[0].LabelAngle = -90;
         chart1.Series[0].Points[i].AxisLabel = sday.ToString("dd/MM/yyyy");
         sday = sday.AddDays(1);
         i++;
}
4

1 回答 1

2

我找到了这样做的方法:

chart1.ChartAreas[0].CursorX.IntervalType = DateTimeIntervalType.Auto;
chart1.ChartAreas[0].CursorX.Interval = 1;

并让 Visual Studio 为您完成这项工作。

于 2012-05-30T18:32:29.133 回答