折磨我的mschart问题
看下面的代码
private void ShowPoints()
{
//make the chart can scroll and zoom
Chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
Chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
Chart1.ChartAreas[0].CursorX.Interval = 1;
Chart1.ChartAreas[0].CursorX.IntervalType = DateTimeIntervalType.Days;//notice here
Chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
Chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;
//Chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm";
// Populate series data
double[] yValues = { 2.8684, 2.8994, 2.9252, 2.9557, 2.9714, 2.9136, 3.0097, 2.8994, 2.9854, 2.8993, 2.9646, 2.9140 };
DateTime currentDate = DateTime.Now;
Random random = new Random();
Chart1.Series["Series1"].Points.Clear();
for(int pointIndex = 0; pointIndex < 12; pointIndex++)
{
Chart1.Series["Series1"].Points.AddXY(currentDate, yValues[pointIndex]);
currentDate = currentDate.AddDays(random.Next(1, 5));//notice here
}
}
上面的代码工作正常,可以进行缩放并能拖动滚动条和scroll滚动条(就是滚动条可以拖动并且点击滚动条空白的地方也能移动滚动条。)但如果改成下面的代码,就不能拖动滚动条了,但点击空白的地方还是可以移动的。不知道是为什么,大家有什么办法可以解决吗。
private void ShowPoints()
{
//make the chart can scroll and zoom
Chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
Chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
Chart1.ChartAreas[0].CursorX.Interval = 1;
Chart1.ChartAreas[0].CursorX.IntervalType = DateTimeIntervalType.minutes;//变了,而且改成hours也一样
Chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
Chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;
//Chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm";
// Populate series data
double[] yValues = { 2.8684, 2.8994, 2.9252, 2.9557, 2.9714, 2.9136, 3.0097, 2.8994, 2.9854, 2.8993, 2.9646, 2.9140 };
DateTime currentDate = DateTime.Now;
Random random = new Random();
Chart1.Series["Series1"].Points.Clear();
for(int pointIndex = 0; pointIndex < 12; pointIndex++)
{
Chart1.Series["Series1"].Points.AddXY(currentDate, yValues[pointIndex]);
currentDate = currentDate.Addminutes(random.Next(1, 5));//变了,而且改成hours也一样
}
}
------最佳解决方案--------------------
private void ShowPoints()
{
//绑定 MSCHART
Series series = new Series("series1");
series.Color = Color.Yellow; // 系列的颜色;
series.ChartType = SeriesChartType.Column; //曲线;
series.IsVisibleInLegend = false; //不需要自动生成图例
chart1.Series.Add(series);
//make the chart can scroll and zoom
chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].CursorX.Interval = 1;
chart1.ChartAreas[0].CursorX.IntervalType = DateTimeIntervalType.Minutes;//变了,而且改成hours也一样
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;
chart1.ChartAreas[0].AxisX.IsLabelAutoFit = true;
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm";
// Populate series data
double[] yValues = { 2.8684, 2.8994, 2.9252, 2.9557, 2.9714, 2.9136, 3.0097, 2.8994, 2.9854, 2.8993, 2.9646, 2.9140 };
DateTime currentDate = DateTime.Now;
Random random = new Random();
chart1.Series["series1"].Points.Clear();
for (int pointIndex = 0; pointIndex < yValues.Length; pointIndex++)
{
chart1.Series["series1"].Points.AddXY(currentDate, yValues[pointIndex]);
currentDate = currentDate.AddMinutes(random.Next(600, 601));//变了,而且改成hours也一样
}
}