图表控件X轴不断扩张,它看起来像它不动 [英] Chart control X axis growing and growing and it looks like it not moving

查看:435
本文介绍了图表控件X轴不断扩张,它看起来像它不动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序和实时图表控件收到日期和我的控件中显示这样的:

I have application with real time Chart control that received date and display this on my control:

这是我的控制:

MyObject obj...

Series series = new Series();
series.Color = Color.Blue;
series.ChartType = SeriesChartType.Spline;
series.BorderWidth = 2;
chart1.Series.Add(series);
chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.White;
chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.White;
chart1.ChartAreas[0].AxisX.IsStartedFromZero = true;
chart1.ChartAreas[0].AxisX.IntervalOffsetType = DateTimeIntervalType.Number
;



计时器滴答:

Timer tick:

private void chartTimer_Tick(object sender, EventArgs e)
{
        series.Points.Add(wf.BitsPerSecond * 0.000001);
        chart1.ResetAutoValues();
}



我的问题是,在一开始,这是图:

my problem is that at the beginning this is the graph:

几分钟后,X轴是不断扩张,它看起来像图停下来动人:

After few minutes the X axis is growing and growing and it looks like the graph stop to moving:

我怎样才能确保我的图表将被看的开始?

how can i make sure my graph will be look at the beginning ?

推荐答案

您不断添加指向图表,但千万不要将其删除。所以,当你调用 chart.ResetAutoValues​​(),这台下方的第一个点的x值x轴的最小值,高于最大值(或等于)您的最后一个点的x值。最大不断变得越来越大,但最小永远不会改变,因此,随着时间的推移的图表看起来压缩。你可以开始删除点,一旦达到某个阈值,如:

You keep adding points to the chart, but don't ever remove them. So, when you call chart.ResetAutoValues(), it sets the minimum on the x-axis below the x value of your first point, and the maximum above (or equal to) the x value of your last point. The maximum keeps getting bigger, but the minimum never changes, so the graph looks compressed as time goes on. You can start to remove points once you reach some threshold, like this:

private void chartTimer_Tick(object sender, EventArgs e)
{
    if (series.Points.Count() > 1000) series.Points.RemoveAt(0);
    series.Points.Add(wf.BitsPerSecond * 0.000001);
    chart1.ResetAutoValues();
}

这篇关于图表控件X轴不断扩张,它看起来像它不动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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