How to set different Label in Legend in Pie Chart

前端 未结 1 818
日久生厌
日久生厌 2020-12-11 10:54

I\'m currently doing a window form that have Pie Chart inside.I need to show the percentage of the pie.

But now I have eencountered a problem : When I a

相关标签:
1条回答
  • 2020-12-11 11:42

    Yes, this is easily done by setting the LegendText for each of your DataPoints like this:

    foreach (DataPoint dp in yourSeries.Points) dp.LegendText = yourLabel;
    

    If your x-values contain meaningful numbers you can use them:

    foreach (DataPoint dp in s.Points) dp.LegendText = dp.XValue + "";
    

    But if you added the x-values as strings they are lost and you have to use another source for the LegendTexts.

    If you only have a fixed number of DataPoints you can set the LegendTexts directly:

    yourSeries.Points[0].LegendText = "hi";
    yourSeries.Points[1].LegendText = "ho";
    yourSeries.Points[2].LegendText = "hum";
    

    Note that usually a Legend shows one entry per Series. But for a Pie chart it shows one entry per DataPoint!

    0 讨论(0)
提交回复
热议问题