在MS Chart控件中为x = 0绘制两个y值 [英] Plotting two y-values for x=0 in a MS Chart control
问题描述
我在Windows表格的MS Chart中发现了一个奇怪的行为.
I found a weird behavior in MS Chart for Windows Forms.
比方说,我想要一个散点图,其中包含两个点(1,10)和(1,20).我可以通过这种方式做到这一点:
Let's say I want to have a scatter plot with two points (1,10) and (1,20). I can do that in this way:
....
Series series = new Series();
series.ChartType = SeriesChartType.Point;
double[] x = { 1, 1 };
double[] y = { 10, 20 };
series.Points.DataBindXY(x, y);
那很好.但是现在我希望得到相同的结果,但是两个x值都应为0
.
That works fine. But now I want the same result, but both x-values should be 0
.
double[] x = { 0, 0 };
double[] y = { 10, 20 };
series.Points.DataBindXY(x, y);
在这种情况下,图表控件会在自动生成的" x位置1和2处创建两个数据点.它只是忽略给定的x值.如果我使用,则是相同的行为
In that case the chart control creates two data points at 'autogenerated' x positions 1 and 2. It just ignores the given x-values. It is the same behavior if I use
series.Points.AddXY(0, 10);
series.Points.AddXY(0, 20);
对于两个以上的数据点,我得到相同的效果.因此,事实证明,如果至少有一个x值不为零,则散点图将不起作用.
I get the same effect for more than two data points. So it turns out that scatter plot does not work if not at least one x-value is nonzero.
我认为可能的解决方法是使用多个序列,但这是不可接受的.
I think a possible workaround would be to use multiple series, but that is inacceptable.
有人对此行为有解释或针对此问题的解决方案吗?
Does anyone have a explanation for this behavior or a solution for this problem?
推荐答案
我自己找到了一个解决方案:
I found a solution by myself:
您必须添加
series.CustomProperties = "IsXAxisQuantitative=True";
您的代码.因此,x值实际上被视为值.我不知道如果使用BindXY函数,为什么这不言而喻.
to your code. So the x-values really are treated as values. I don't know why this is not self-evident if I use the BindXY function.
这篇关于在MS Chart控件中为x = 0绘制两个y值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!