【问题标题】:Prevent ZedGraph from drawing missing points防止 ZedGraph 绘制缺失点
【发布时间】:2020-08-05 19:20:28
【问题描述】:

当 GraphPane 仅包含一个 CurveItem rime 系列时,一切正常,每个新点都添加到图表中并显示,没有间隙或缺失值。

然后,我将第二个时间序列添加到同一个 GraphPane 中,这些时间序列中的数据点以不同的频率出现,因此它们在 X 轴上有不同的值,X 轴的数据类型设置为DateAsOrdinal。此时,当我向每个时间序列添加数据点时,图表似乎试图同步两个时间序列中的数据点,并用一些平均中间值填充第一个时间序列中的数据点和第二个时间序列中的数据点之间的差异。

示例

var seriesA = new PointPairList();
var seriesB = new PointPairList();

var valuesA = new [] 
{
  new PointPair { DateTime.Parse("2006-01-01", 5) },
  new PointPair { DateTime.Parse("2006-01-02", 25) },
  new PointPair { DateTime.Parse("2006-01-03", 15) },
  new PointPair { DateTime.Parse("2006-01-04", 0) },
  new PointPair { DateTime.Parse("2006-01-05", 10) }
};

for (var i = 0; i < 5; i++) 
{
  control.GraphPane.seriesA.Add(valuesA[i]);
}

// Until now, everything works fine, now I try to add one point to the second seriesB 

control.GraphPane.seriesB.Add(new PointPair { DateTime.Parse("2006-02-05", 10) });

// At this moment, chart identifies that the average interval between dates is 1 day 
// and try to populate missing spaces between seriesA (2006-01-05) and seriesB (2006-02-05) 
// and automatically adds 30 more points to seriesA and 34 points to seriesB to make them equal

最后,我希望 seriesA 有 5 个点,seriesB 有 1 个点,但 ZedGraph 尝试强制执行相同数量的数据点,即 35 个。

问题

如何确保我在图表上看到的只是我自己添加的点?

图表设置

control.AutoScroll = true;
control.IsEnableHPan = true;
control.IsEnableVPan = true;
control.IsEnableHZoom = false;
control.IsEnableVZoom = false;
control.IsShowHScrollBar = false;
control.IsShowVScrollBar = false;
control.IsAutoScrollRange = true;
control.IsShowPointValues = true;
control.IsSynchronizeXAxes = true;
control.IsEnableWheelZoom = false;
control.IsZoomOnMouseCenter = false;

窗格设置

area.XAxis.Title.Text = string.Empty;
area.XAxis.Type = AxisType.DateAsOrdinal;
area.XAxis.Scale.Format = "dd-MM-yyyy HH:mm";
area.XAxis.MajorGrid.IsVisible = true;
area.XAxis.Scale.MinAuto = false;
area.XAxis.Scale.MaxAuto = false;

area.YAxis.Title.Text = string.Empty;
area.YAxis.MajorGrid.IsVisible = true;
area.YAxis.Scale.MinAuto = true;
area.YAxis.Scale.MaxAuto = true;

【问题讨论】:

    标签: c# zedgraph


    【解决方案1】:

    以下代码,对我而言,使用您的数据生成正确的图表。

    resulting plot

            var area = control.GraphPane;
            area.Title.Text = string.Empty;
            area.XAxis.Type = AxisType.DateAsOrdinal;
            area.XAxis.MajorGrid.IsVisible = true;
            area.YAxis.MajorGrid.IsVisible = true;
            area.XAxis.Scale.Format = "dd-MM-yyyy";
            area.XAxis.Title.Text = string.Empty;
            area.YAxis.Title.Text = string.Empty;
    
            var seriesA = new PointPairList()
            {
                new PointPair(new XDate(DateTime.Parse("2006-01-01")), 5) ,
                new PointPair(new XDate(DateTime.Parse("2006-01-02")), 25) ,
                new PointPair(new XDate(DateTime.Parse("2006-01-03")), 15) ,
                new PointPair(new XDate(DateTime.Parse("2006-01-04")), 0) ,
                new PointPair(new XDate(DateTime.Parse("2006-01-05")), 10) ,
            };
    
            var seriesB = new PointPairList()
            {
                new PointPair(new XDate(DateTime.Parse("2006-02-05")), 10)
            };
         
            area.AddCurve("a", seriesA, Color.Red);
            area.AddCurve("b", seriesB, Color.Blue);
              
            control.AxisChange();
            control.Invalidate();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-23
      • 1970-01-01
      • 2018-01-11
      • 2014-06-09
      • 1970-01-01
      • 1970-01-01
      • 2016-02-18
      • 1970-01-01
      相关资源
      最近更新 更多