C#在图表上添加到Y值 [英] C# Add to Y value on chart
问题描述
我正在尝试将列表添加到图表。此列表包含2和4。
I am trying to add a List to a chart. This list contains a 2 and a 4.
foreach (decimal D in numbers)
{
barChart.Series[0].Points.AddXY(1, D);
}
它需要在X轴上将D添加到索引1。但是,这仅在X1输出4,而不是6。当它到达列表中的4时,它将覆盖那里的2,而不是添加到其中(使6)。如何使它增加而不是覆盖?
It needs to add D to index 1 on the X axis. However, this only outputs 4 rather than six at X1. When it gets to the 4 in the list, it overwrites the 2 that is there, rather than adding to it (making 6). How do I make it add rather than overwrite?
编辑:我显然没有提供足够的信息。我正在使用Windows窗体。我使用的图表位于Visual Studio 2015的数据部分。
I did not give enough information apparently. I am using Windows Forms. The chart I am using is in the Data section of Visual Studio 2015.
推荐答案
您误解了<$ c $的含义c> AddXY 方法。
它不会更改y-或任何值。
It doesn't change the y- or any values.
AddXY
意味着将一个新的 DataPoint
添加到 Points
集合中。
AddXY
means that a new DataPoint
is added to the Points
collection.
在您的代码中,每个x值的 1
和两点的y值是 2
和 4
。为此,您可能会写:
In your code each will have an x-value of 1
and the y-values of the two points are 2
and 4
. To do so you would write, maybe:
barChart.Series[0].Points[0].YValues[0] += D;
如果数字是小数,则需要转换为双精度数,这是所有数字的基数类型图表值:
If your numbers are decimals you will need to cast to double, which is the base number type for all Chart values:
barChart.Series[0].Points[0].YValues[0] += (double)D;
这篇关于C#在图表上添加到Y值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!