简体   繁体   中英

C#: ZedGraph Show All Points of Zoomed Area

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM