如何在饼图中设置图例中的不同标签

我正在做一个里面有Pie Chart的窗口表格。我需要显示饼图的百分比。

但现在我遇到了一个问题:当我将#PERCENT{P2}添加到系列时, Pie Chart将显示如下:

在此处输入图像描述

但如果我删除它, Pie Chart将显示如下

在此处输入图像描述

是否有可能像这样制作Pie Chart在此处输入图像描述

我的代码:

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

是的,这可以通过为每个DataPoints设置LegendText来轻松完成,如下所示:

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

如果您的x值包含有意义的数字,您可以使用它们:

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

但是如果你将x值作为字符串添加它们就会丢失 ,你必须使用LegendTexts另一个源代码。

如果您只有固定数量的DataPoints ,则可以直接设置LegendTexts

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

请注意,通常Legend会在每个Series显示一个条目。 但对于Pie它显示每个DataPoint一个条目!