添加一个滚动条MS图表控件C# [英] Adding a scroll bar to MS Chart control C#

查看:553
本文介绍了添加一个滚动条MS图表控件C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请大家明白,我知道有关于这个问题的其他线程,但我的需求是不同的。

please understand that I know there are other threads concerning this issue, but my needs are different.

基本上我之前见过的人说要实现与MSChart的滚动条,他们使用

Basically before I seen people saying to implement a scroll bar with MSChart they use the

.Size = ...

.Size = ...

.View = ...

.View = ...

但是,这使滚动条自动AP $ P $相提并论,这滚动栏包含一个按钮,点击它时,导致栏消失,使得图表显示所有数据,并没有带回滚动条的方式图表而不需要重新启动应用程序。

But, this make a scroll bar automatically apprear, and this scroll bar contains a button that when clicked causes the bar to vanish, making the chart show all data, and no way of bringing back the scroll bar to the chart without restarting the app.

于是我问,请,有没有一种方法来incorportate我图的X轴水平滚动条?我需要的,这样我可以查看100个第二块的块我的图表数据。

So I ask, please, Is there a way to incorportate a horizontal scroll bar on the X-axis of my Chart? I am needing on so that I can view my chart data on blocks of 100 second blocks.

即。 0 - 100,然后单击sroll栏会带给我100 - 200块

i.e. 0 - 100, then click sroll bar will bring me to 100 - 200 block.

感谢您提前家伙!!!!!在C#还IM编码

Thank you in advance guys!!!!! im coding in C# also

推荐答案

下面是你需要什么一个例子:结果
 (尝试一下,只需创建一个窗体中添加一个MSChart的,并调用下面的方法)

Here's an example of what you need:
(to try it, just create a form, add a mschart and call the following method)

private void FillChart()
{
    int blockSize = 100;

    // generates random data (i.e. 30 * blockSize random numbers)
    Random rand = new Random();
    var valuesArray = Enumerable.Range(0, blockSize * 30).Select(x => rand.Next(1, 10)).ToArray();

    // clear the chart
    chart1.Series.Clear();

    // fill the chart
    var series = chart1.Series.Add("My Series");
    series.ChartType = SeriesChartType.Line;
    series.XValueType = ChartValueType.Int32;
    for (int i = 0; i < valuesArray.Length; i++)
        series.Points.AddXY(i, valuesArray[i]);
    var chartArea = chart1.ChartAreas[series.ChartArea];

    // set view range to [0,max]
    chartArea.AxisX.Minimum = 0;
    chartArea.AxisX.Maximum = valuesArray.Length;

    // enable autoscroll
    chartArea.CursorX.AutoScroll = true;

    // let's zoom to [0,blockSize] (e.g. [0,100])
    chartArea.AxisX.ScaleView.Zoomable = true;
    chartArea.AxisX.ScaleView.SizeType = DateTimeIntervalType.Number;
    int position = 0;
    int size = blockSize;
    chartArea.AxisX.ScaleView.Zoom(position, size);

    // disable zoom-reset button (only scrollbar's arrows are available)
    chartArea.AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;

    // set scrollbar small change to blockSize (e.g. 100)
    chartArea.AxisX.ScaleView.SmallScrollSize = blockSize;
}


快照:

这篇关于添加一个滚动条MS图表控件C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆