c#如何为图表上的每个点添加标签? (没有全部相同)

时间:2016-09-01 19:03:45

标签: c# charts label

现在,我有一个图表,我添加Y值点。其次是标签。但是当我继续添加更多点时,所有点的当前标签都是相同的。有没有办法让每个标签都有正确的标签?

    chart1.Series["Series1"].Points.AddY(Height);
    chart1.Series["Series1"].Label = Age;

也许,我可以在同一行中添加标签Age我添加数据点高度? (例如。(身高,标签=年龄))?

以上是我试图解决的基本概念。我正在做的事情的本质是在" height"参数符合我的标准(高于1.78)。然后,在将高度字符串转换为double后,我将其添加到图表图中。然后在UDP中添加相应的标签。唯一的问题是,在下一点,我的所有点在更新时都会得到相同的标签。

年龄是一个字符串,我用作标签,不能在Xaxis或Yaxis中使用

if (numberSize>paramSize)     //if myHeight is greater than paramHeight
{
    if (_form.listBox1.InvokeRequired)
        _form.listBox1.Invoke((MethodInvoker)delegate ()
        {
            _form.listBox1.Items.Insert(0, valueSet);
            // below just converting to double to be fitted in my chart
            double heightDouble = Convert.ToDouble(Height);
            //And now I'd like to add a point from the UDP and then its label
            _form.chart1.Series["Series1"].Points.AddY(heightDouble);
            _form.chart1.Series["Series1"].Label = Age;
        }
        );
}

由于

P.S。为了使事情更清楚,下面是图表。在Y轴上是高度。 X轴只是点的迭代(例如,第二点,第三点等),标签是年龄。最后一个年龄为72岁,但每个标签设置为72,不仅仅是当前的标签。 enter image description here

1 个答案:

答案 0 :(得分:2)

当我使用TaW的答案时,它有效。

int idx = _form.chart1.Series["Series1"].Points.AddY(heightDouble);
_form.chart1.Series["Series1"].Points[idx].Label = ...
相关问题