问题
I am plotting to my data to ZedGraph. Using FileStream
to read files. Sometimes my data is greater than 200 megabyte. To draw this amount of data i should calculate peak values or must apply a window. However i want to see the all points of zoomed area. Please share any suggestion.
PointPairList list1 = new PointPairList();
int read;
int count = 0;
while (file.Position < file.Length)
{
read = file.Read(mainBuffer, 0, mainBuffer.Length);
for (int i = 0; i < read / window; i++)
{
list1.Add(count++, BitConverter.ToSingle(mainBuffer, i * window));
count++;
}
}
myCurve1 = zgc.MasterPane.PaneList[1].AddCurve(null, list1, Color.Lime, SymbolType.None);
myCurve1.IsX2Axis = true;
zgc.MasterPane.PaneList[1].XAxis.Scale.MaxAuto = true;
zgc.MasterPane.PaneList[1].XAxis.Scale.MinAuto = true;
zgc.AxisChange();
zgc.Invalidate();
window=2048
for file size between 100 megabyte to 300 megabyte.
回答1:
Instead of using a PointPairList
, I would suggest to use a FilteredPointList
instead. By this way, you can keep every points in memory, ZedGraph will only show the points that are necessary for display.
The FilteredPointList
class is well explained here.
You will have to change your code a bit this way:
// Load the X, Y points in two double arrays
// ...
var list1 = new FilteredPointList(xArray, yArray);
// ...
// Use the ZoomEvent to adjust the bounds of the filtered point list
void zedGraphControl1_ZoomEvent(ZedGraphControl sender, ZoomState oldState, ZoomState newState)
{
// The maximum number of point to displayed is based on the width of the graphpane, and the visible range of the X axis
list1.SetBounds(sender.GraphPane.XAxis.Scale.Min, sender.GraphPane.XAxis.Scale.Max, (int)zgc.GraphPane.Rect.Width);
// This refreshes the graph when the button is released after a panning operation
if (newState.Type == ZoomState.StateType.Pan)
sender.Invalidate();
}
Edit
If you can't not host all the points in memory, then you will have to provide your own IPointList
implementation for ZedGraph using the logic in the code you describe above. You can inspire from the FilteredPointList itself.
I would use the SetBounds
method to preload the points from the disk, based on the decimation algorithm you already implemented, using the min, max and MaxPts in parameters.
来源:https://stackoverflow.com/questions/19250775/c-zedgraph-show-all-points-of-zoomed-area