Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用对数缩放向图表添加空点_C#_Mschart - Fatal编程技术网

C# 使用对数缩放向图表添加空点

C# 使用对数缩放向图表添加空点,c#,mschart,C#,Mschart,我正在使用C#图表来显示/比较一些数据。我将图形比例更改为对数(因为我的数据点存在巨大差异),但由于对数比例不支持零值,因此我只想为此类情况添加一个空点(或跳过数据点)。我尝试了以下但不起作用的所有碰撞: if (/*the point is zero*/) { // myChart.Series["mySeries"].Points.AddY(null); // or // myChart.Series["mySeries"].Points.AddY(); //

我正在使用
C#
图表
来显示/比较一些数据。我将图形比例更改为
对数
(因为我的数据点存在巨大差异),但由于
对数
比例不支持
值,因此我只想为此类情况添加一个空点(或跳过数据点)。我尝试了以下但不起作用的所有碰撞:

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

可以添加一个空点还是跳过一个点?

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

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

这看起来像零

在我的例子中,没有与以下
serieChartType
s崩溃:

Column, Doughnut, FastPoint, Funnel, Kagi, Pie, Point, Polar, Pyramid, Radar, Renko, Spline, SplineArea, StackedBar, StackedColumn, ThreeLineBreak
Area, Bar, Column, Doughnut, FastPoint, Funnel, Line, Pie, Point, Polar, Pyramid, Radar, Renko, Spline, SplineArea, StackedArea, StackedArea100, StackedBar, StackedBar100, StackedColumn, StackedColumn100, StepLine, ThreeLineBreak
另一种方式是空点的内置概念:

if (myChart.ChartAreas[0].AxisY.IsLogarithmic && y == 0)
    myChart.Series["mySeries"].Points.Add(new DataPoint { IsEmpty = true });
这似乎缺少一点(一个缺口):

在我的例子中,没有与以下
serieChartType
s崩溃:

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

第二种方法感觉像是右边的方法(根据设计)。第一个看起来像是一个黑客,它意外地出现在工作中。

你可以玩个把戏。显然,你必须清除你的序列。开始向空点集合添加点时,将从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);
}

对于条形图类型,它看起来像一个缺少的值。

如果它在一个循环中,你不能继续吗?它是一个循环,我可以继续,但不会添加一个空点。我已经标记了我的X轴,因此如果我在下一个循环中继续循环,我将在我的X值中添加一个错误的Y值。我有相同的问题:(@shady sherif,如果你仍然想知道如何做,我找到了一些答案。@shady sherif,你说的“post it”是什么意思?)我已经做了,就在发布我的评论之前。然后我在这里发表评论,让你们知道问题已经解决了,)我投了赞成票。但是,如果图表类型是
?然后,您的方法会给出类似于重复值的值,而不是空值。@Alex谢谢。我承认我的解决方案有缺点。但任何人都是如此。这取决于OP决定在这种情况下使用哪一个来获得最佳结果。