如何在图表中对齐索引系列 [英] How to align indexed Series in a Chart

查看:280
本文介绍了如何在图表中对齐索引系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当通过设置系列为 us / library / system.windows.forms.datavisualization.charting.series.isxvalueindexed%28v = vs.110%29.aspx?f = 255& MSPPError = -2147217396rel =nofollow> 系列.IsXValueIndexed true 图表要求所有系列 aligned

When setting a Series to be indexed by setting the Series.IsXValueIndexed to true the chart requires all Series to be aligned:


如果显示多个系列,那么所有系列必须对齐 - 也就是说,
的数据点数相同,对应的点必须有
个相同的X值。

If you are displaying multiple series and at least one series uses indexed X-values, then all series must be aligned — that is, have the same number of data points—and the corresponding points must have the same X-values.

如何在中添加必要的 Emtpy DataPoints 系列 c>

推荐答案

此例程首先收集所有 / code> $

This routine first collects all values in all Series in a collection of doubles.

然后它遍历所有系列和所有值,并插入缺少的空 DataPoints

Then it loops over all Series and over all values and inserts the missing empty DataPoints:

void AlignSeries(Chart chart)
{
    var allValues = chart.Series.SelectMany(s => s.Points)
                          .Select(x=>x.XValue).Distinct().ToList();
    foreach (Series series in chart.Series)
    {
        int px = 0;    //insertion index
        foreach(double d in allValues )
        {
            var p = series.Points.FirstOrDefault(x=> x.XValue == d);
            if (p == null)  // this value is missing
            {
                DataPoint dp = new DataPoint(d, double.NaN);
                dp.IsEmpty = true;
                series.Points.Insert(px, dp);
            }
            px++;
        }
    }
}

请注意, 。


  • 您的x值已正确设置,即它们被添加为 numbers DateTimes 。如果您将它们添加为 strings ,它们都是 0 ,索引是没有意义的。

  • that your x-values are correctly set, i.e. they were added as numbers or DateTimes. If you added them as strings they all are 0 and indexing makes no sense.

DataPoints 是以升序顺序添加的。这并不总是这样,特别是当绘制 LineCharts 时。

that the DataPoints were added in ascending order. This is not always the case, especially when plotting LineCharts. However indexing these makes no sense either.

另外请注意,您可以设置几个选项来处理通过设置系列中创建空数据点 de / library / system.windows.forms.datavisualization.charting.series.emptypointstyle(v = vs.110).aspxrel =nofollow> Series.EmptyPointStyle ,它源自 DataPointCustomProperties

Also note that you can set several options of how to treat Empty DataPoints in a Series by setting properties in the Series.EmptyPointStyle, which is derived from DataPointCustomProperties.

c> Color 像这样:

So you could set their Color like this:

 someSeries.EmptyPointStyle.Color = Color.Red;

这篇关于如何在图表中对齐索引系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆