簡體   English   中英

c#如何為圖表上的每個點添加標簽? (沒有一個都一樣)

[英]c# how to add label for each point on chart? (without all of them the same)

現在,我有一個圖表,並添加了Y個價值點。 后跟標簽。 但是,當我繼續添加更多點時,所有點的當前標簽都相同。 有什么辦法可以使每個標簽都有正確的標簽?

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

也許可以在添加數據點高度的同一行中添加標簽Age? (例如,(身高,標簽=年齡))?

以上是我要解決的基本概念。 我正在做的本質是當“高度”參數符合我的標准時(高於1.78)獲得UDP提要。 然后,將高度字符串轉換為兩倍后,將其添加到圖表中。 然后在UDP中添加相應的標簽。 唯一的問題是,在接下來的一點上,我的所有積分在更新時都具有相同的標簽。

年齡是一個字符串,我用作標簽,請勿在X軸或Y軸中使用

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;
        }
        );
}

謝謝

PS為了使事情更清楚,下面是圖表。 在Y軸上是高度。 X軸只是該點(例如第二點,第三點等)的迭代,標簽是年齡。 上一個年齡是72歲,但每個標簽都被設置為72歲,不僅適用於當前年齡。 在此處輸入圖片說明

當我使用TaW的答案時,它起作用了。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM