Chart Compression

橙三吉。 提交于 2019-12-29 01:28:11

问题


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.

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.

回答1:


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;


来源:https://stackoverflow.com/questions/23542701/chart-compression

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!