图表控制X轴生长和增长,它看起来像它不移动 [英] Chart control X axis growing and growing and it looks like it not moving

查看:178
本文介绍了图表控制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
;

计时器计时:

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天全站免登陆