ZedGraph:仅获取可见曲线点的PointPairList

3

如何仅获取可见曲线数据的PointPairList,而不是Curveitem列表中的所有点?该列表应在缩放或平移时动态更改。

谢谢。


1
你找到答案了吗? - Vic
3个回答

2

看起来没有一个ZedGraph API方法可以为您完成这项工作。但是,下面的代码演示了一个VisiblePoints方法,它返回一个PointPairList,并在一个非常特定的ZedGraph使用情况下工作。

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using ZedGraph;

namespace ZedGraphMain
{
    public class ZedGraphDemo : Form
    {
        public ZedGraphDemo()
        {
            var graphControl = new ZedGraphControl();
            graphControl.Dock = DockStyle.Fill;
            graphControl.IsShowPointValues = true;
            Controls.Add(graphControl);
            var points = new PointPairList();
            for (double i = 0; i <= 5.0; i += 1)
                points.Add(i, i);

            var curve = graphControl.GraphPane.AddCurve("A Label", points, Color.ForestGreen);

            graphControl.RestoreScale(graphControl.GraphPane);
            graphControl.ZoomEvent += (_, __, ___) => LogVisibility(graphControl, curve, points);
        }

        private static PointPairList VisiblePoints(ZedGraphControl control, LineItem lineItem, PointPairList points)
        {
            var pointPairList = new PointPairList();
            pointPairList.AddRange(points.Where(pp => IsVisible(control, lineItem, pp)).ToList());
            return pointPairList;
        }

        private static bool IsVisible(ZedGraphControl control, LineItem lineItem, PointPair point)
        {
            GraphPane pane = control.GraphPane;
            Scale xScale = lineItem.GetXAxis(pane).Scale;
            Scale yScale = lineItem.GetYAxis(pane).Scale;
            return point.X > xScale.Min && point.X < xScale.Max && point.Y > yScale.Min && point.Y < yScale.Max;
        }

        private static void LogVisibility(ZedGraphControl control, LineItem lineItem, PointPairList points)
        {
            List<PointPair> visiblePoints = VisiblePoints(control, lineItem, points);
            Console.Out.WriteLine(DateTime.Now + ": " + string.Join(",", visiblePoints.Select(pp => string.Format("({0:N1}, {1:N1})", pp.X, pp.Y))));
        }
    }
}

1

0

我相信PointPairList始终包含所有点。

绘制的点总是存在的,只是它们如何随着缩放和平移而转换为像素。

我知道我需要为大数据集创建自己的AverageFilteredList。我有成千上万的点,由于内存使用而导致应用程序停滞不前(实现已删除以简洁为要):

public class AverageFilteredPointList : IPointList 
{
  <snip>

  public int Count { get; set; }
  public int MaxPts { get; set; }

  public PointPair this[int index] { get; set; }
  public void SetBounds(double min, double max, int maxPts) { }
}

如果您想收集可见的“点”信息,我认为您将不得不实现自己的IPointList类,以处理其自身内部点的缩放/平移。

此外,我不确定这是否会对您有所帮助,但您可以使用以下GraphPane函数来确定像素位置所在的实际DataPoint:

ReverseTransform(pt, out xSampleData, out ySampleData);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接