Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

c# - How to set different Label in Legend in Pie Chart

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 add this #PERCENT{P2} to series the Pie Chart will show like this:

enter image description here

But if I remove it, the Pie Chart will show like this

enter image description here

Is there possible to make the Pie Chart Like this?enter image description here

My Code:

DataTable dt = new DataTable();
        dt.Columns.Add("completed", typeof(string));
        dt.Columns.Add("no", typeof(int));
        int noin = allitem - intime;
        dt.Rows.Add("Complete In Time", intime);
        dt.Rows.Add("OverDue", noin);

        chart1.DataSource = dt;

        chart1.DataBind();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...