.Net Chart Control Auto Scroll/Disable Auto Scale
I am current building an application that graphs streaming data. I can receive and add data points t开发者_Python百科o the chart just fine, but after every point is added, the graph alters its scale to include all the data points automatically(ie. the points get closer together as more are added). How can I turn this off?
Ideally, I would like the graph to simply scroll along the x axis rather than setting the scale each time a point is added. What is the best way to do this?
Here is the code I use for adding a data point as data arrives on the serial port:
chart1.Series["Series1"].Points.AddY(parsed);
The graph is just a default fast line plot. Here are screen captures of the graph plotting data over time. As you can see, it just compresses the graph over time rather than just leaving the scale alone and scrolling to the right.
This will disable auto-scaling:
chart1.ChartAreas[0].AxisY.ScaleBreakStyle.Enabled = false;
chart1.ChartAreas[0].AxisY.Maximum = 0.3;
chart1.ChartAreas[0].AxisY.Minimum = -0.3;
Iv'e done this in the following manner :
Edit is a mock which adds points on each timer tick the minimum and maximum values are incremented , so the part shown is incremented and so a scrolling effect occurs .
private void mockTimerTick(object sender, EventArgs e)
{
int i;
if (isRunning)
return;
lock (_syncObj)
{
isRunning = true;
for (i = currentOffset; i < samplesPerSegment + currentOffset; i++)
{
_series.Points.AddXY(mockPoints[i].X, mockPoints[i].Y);
if (i >= _chart.ChartAreas["ChartArea1"].AxisX.Maximum)
{
_chart.ChartAreas["ChartArea1"].AxisX.Maximum++;
_chart.ChartAreas["ChartArea1"].AxisX.Minimum++;
_chart.ChartAreas["ChartArea1"].AxisX.ScaleView.Scroll(_chart.ChartAreas["ChartArea1"].AxisX.Maximum);
}
}
isRunning = false;
}
currentOffset = i;
}
精彩评论