【问题标题】:Adding an empty point to a charts with logarithmic scaling使用对数缩放向图表添加空点
【发布时间】:2012-09-17 17:40:09
【问题描述】:

我正在使用C# charts 来显示/比较一些数据。我将图形比例更改为logarithmic(因为我的数据点有很大的差异),但由于logarithmic 缩放不支持zero 值,我只想为此添加一个空点(或跳过一个数据点)案例。我已经尝试了以下但不起作用并且所有崩溃:

if (/*the point is zero*/)
{
    // myChart.Series["mySeries"].Points.AddY(null);
    // or
    // myChart.Series["mySeries"].Points.AddY();
    // or just skip the point
}

是否可以添加一个空点或只是跳过一个点?

【问题讨论】:

  • 如果在循环中,你就不能continue 吗?
  • 这是一个循环,我可以继续,但这不会添加一个空点。我已经标记了我的 X 轴,所以如果我在下一个循环中继续循环,我会在我的 X 值中添加一个错误的 Y 值
  • 我遇到了同样的问题 :(
  • @shady sherif,如果您仍然想知道如何做到这一点,我找到了一些答案。
  • @shady sherif,'post it' 是什么意思?)我已经这样做了,就在发表评论之前。然后我在这里评论让你知道问题已经解决了,)

标签: c# mschart


【解决方案1】:

我找到了两种解决问题的方法。

一个正在使用double.NaN(突然!):

if (myChart.ChartAreas[0].AxisY.IsLogarithmic && y == 0)
    myChart.Series["mySeries"].Points.AddY(double.NaN);
    // or ...Points.Add(double.NaN)

这看起来为零

在我的情况下,它没有因关注SeriesChartTypes 而崩溃:

Column, Doughnut, FastPoint, Funnel, Kagi, Pie, Point, Polar, Pyramid, Radar, Renko, Spline, SplineArea, StackedBar, StackedColumn, ThreeLineBreak

另一种方式是空点的内置概念:

if (myChart.ChartAreas[0].AxisY.IsLogarithmic && y == 0)
    myChart.Series["mySeries"].Points.Add(new DataPoint { IsEmpty = true });

这看起来像是一个缺失点(一个缺口):

在我的情况下,它没有因关注SeriesChartTypes而崩溃:

Area, Bar, Column, Doughnut, FastPoint, Funnel, Line, Pie, Point, Polar, Pyramid, Radar, Renko, Spline, SplineArea, StackedArea, StackedArea100, StackedBar, StackedBar100, StackedColumn, StackedColumn100, StepLine, ThreeLineBreak

第二种方法感觉就像是正确的(按设计)。 第一个看起来像一个hack,意外地似乎起作用了。

【讨论】:

    【解决方案2】:

    你可以做一个小把戏。你显然必须清除你的系列。当您开始向空点集合添加点时,会从 1 开始自动生成 x 坐标。您可以自己创建代理 x 并跳过一些 x 值。

    int x = 0;
    foreach(var y in yValues)
    {
        x++;
        if (myChart.ChartAreas[0].AxisY.IsLogarithmic && y == 0)
            continue;
        myChart.Series["mySeries"].Points.AddXY(x, y);
    }
    

    对于条形图类型,它看起来像是缺失值。

    【讨论】:

    • 我赞成一个好观点。但是如果图表类型是Line 呢?然后你的方法给出了一个看起来像 repeated 值的东西,not 是一个空值。
    • @Alex 谢谢。我承认我的解决方案有弱点。但任何人都是如此。由 OP 决定在这种情况下使用哪一个以获得最佳结果。
    猜你喜欢
    • 2015-05-20
    • 2011-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多