Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
776 views
in Technique[技术] by (71.8m points)

c# - Chart control X axis growing and growing and it looks like it not moving

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

This is 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:

enter image description here

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

enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...