折磨我的mschart问题

aha100 2010-05-26 12:25:33
看下面的代码

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也一样

}

}

...全文
383 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
能能爸 2012-07-13
  • 打赏
  • 举报
回复
为什么我的mschart控件没curseX属性
aha100 2011-03-22
  • 打赏
  • 举报
回复
好长时间了,回来结下帖子。
问题解决了,不过mschart真的是特别的东西,大家用的时候注意curseX的设置与scrollbar的设置还有axisX的设置要对应。
如有问题找我。
wo6522317 2010-05-27
  • 打赏
  • 举报
回复

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也一样
}
}
aha100 2010-05-27
  • 打赏
  • 举报
回复
谢谢wo6522317兄,你的认真我很欣赏。
皇城龙三 2010-05-26
  • 打赏
  • 举报
回复
先看看,研究一下。
wo6522317 2010-05-26
  • 打赏
  • 举报
回复
帮顶...
也找不出原因,
不过修改这个随机范围random.Next(60, 120) 或者增加数据量,就可以解决这个问题;
aha100 2010-05-26
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 guoweidong 的回复:]
Chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true; 可以缩放 上面的是可使用滚动条
[/Quote]

晕,给的代码里不就有这句话吗
aha100 2010-05-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 guoweidong 的回复:]
Chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;
加上这个看看了,没用过,也没试过~!
[/Quote]
这个我试过的,没用。而且我上面给的代码里不就有的吗,其实添加与否都一样的。
guoweidong 2010-05-26
  • 打赏
  • 举报
回复
Chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true; 可以缩放 上面的是可使用滚动条
guoweidong 2010-05-26
  • 打赏
  • 举报
回复
Chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;
加上这个看看了,没用过,也没试过~!
aha100 2010-05-26
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wo6522317 的回复:]
帮顶...
也找不出原因,
不过修改这个随机范围random.Next(60, 120) 或者增加数据量,就可以解决这个问题;
[/Quote]


我试了下,也不行的啊。兄台仅仅是改了范围或增加了数据量吗???好像不行啊。

4,816

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧