3

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

谢谢。

4

3 回答 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))));
        }
    }
}
于 2015-02-11T10:22:00.330 回答
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);
于 2013-05-23T20:05:14.650 回答
0

The existing FilteredPointList matches exactly your requirements.

It contains a detailed explanation about how to use it as well as a link to a ZedGraph wiki.

于 2013-11-08T07:44:26.027 回答