【问题标题】:C#: ZedGraph Show All Points of Zoomed AreaC#: ZedGraph 显示缩放区域的所有点
【发布时间】:2013-10-09 20:30:12
【问题描述】:

我正在将我的数据绘制到 ZedGraph。使用FileStream 读取文件。有时我的数据大于 200 兆字节。要绘制这么多数据,我应该计算峰值或必须应用一个窗口。但是我想查看缩放区域的所有点。请分享任何建议。

        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 用于 100 兆字节到 300 兆字节之间的文件大小。

【问题讨论】:

    标签: c# list zedgraph


    【解决方案1】:

    我建议不要使用PointPairList,而是使用FilteredPointList。通过这种方式,您可以将每个点保存在内存中,ZedGraph 只会显示需要显示的点。

    FilteredPointList 类很好解释了here

    您将不得不以这种方式稍微更改您的代码:

    // 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();
    }
    

    编辑

    如果您不能在内存中托管所有点,那么您将必须使用上面描述的代码中的逻辑为 ZedGraph 提供自己的IPointList 实现。您可以从 FilteredPointList 本身获得灵感。

    我将使用SetBounds 方法从磁盘预加载点,基于您已经实现的抽取算法,使用参数中的最小值、最大值和 MaxPts。

    【讨论】:

    • 要使用 FilteredPointList 我需要数组中的所有数据,不是吗?如果是,由于内存不足异常,我无法一次将整个数据存储在数组中。
    • 感谢您的回复。我会尝试自定义它。
    猜你喜欢
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多