Question

I am writing a C# desktop application that requires a graphical representation (XoY) of some values (Y - value, X - (in) time).

chart1.Series[0].Points.AddXY(time, new Random().Next(-325, 531)); //this operation occurs at a set interval

The operation does its job, adding up values; however, in time the chart has the tendency to "squeeze" itself which makes interpreting it a much harder task.

phase0 phase1 phase2

I want to make the graphic generate a better output, despite the number of points.

Notes

  1. I consider that a good example of graphical representation would be one generated by an oscilloscope.
  2. The chart is an spline.
  3. The point addition is triggered upon a tick of a timer.
Was it helpful?

Solution

Depending on what you want there are several choices. My guess is that you want to keep all data points and simply want to add a scrollbar. To do you can write:

ChartArea A1 = chart1.ChartAreas["yourChartAreaByNameOrNumber"];
A1.AxisX.ScrollBar.Size = 12;
// show either just the center scroll button..
A2.AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;
// .. or include the left and right buttons:
A1.AxisX.ScrollBar.ButtonStyle = 
    ScrollBarButtonStyles.All ^ ScrollBarButtonStyles.ResetZoom;
// looks better inside, but ymmv
A1.AxisX.ScrollBar.IsPositionedInside = true;
A1.AxisX.ScrollBar.Enabled = true;
A1.AxisX.ScaleView.Size = 100;  // number (!) of data points visible

You may want to play with the size and placement. Please pick the number of data points you want to have visible at any time..

If you want the visible area to follow the new data like in an oscilloscope, you can set the scroll position :

Series S1 = chart1.Series["yourSeriesByNameOrNumber"];
A1.AxisX.ScaleView.Position = S1.Points.Count - A1.AxisX.ScaleView.Size;

Note that you need to set it again after adding any data!

If you also want to let the users adapt the zoom range set

A1.AxisX.CursorX.IsUserSelectionEnabled = true;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top