Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

c# - Chart Compression

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.
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...