我正在绘制我的数据到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 to至300 to之间。
发布于 2013-10-08 20:49:19
我建议不要使用PointPairList,而是使用FilteredPointList。通过这种方式,您可以将每个点保存在内存中,ZedGraph将只显示显示所需的点。
FilteredPointList类得到了很好的解释,这里。
您必须以这样的方式更改代码:
// 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提供自己的ZedGraph实现。您可以从FilteredPointList本身得到启发。
我将使用SetBounds方法从磁盘预加载点,基于您已经实现的抽取算法,使用参数中的min、max和MaxPts。
https://stackoverflow.com/questions/19250775
复制相似问题