我可以在MSChart的饼图标签上显示标签和值

Ric*_*ett 1 c# asp.net data-visualization mschart

我有一个Microsoft Chart Controls类型的Donut类型的图表(在命名空间System.Web.UI.DataVisualization.Charting中).

我绑定到图表系列的数据的类型Dictionary<string, int>是标签是字典的键,值是Value属性.我希望饼图上的标签看起来像这样:Some label (4)"Some label"是字典中条目的键,4是值.

我已经试过的各种组合IsValueShownAsLabelLabelFormat,但是这并没有帮助,因为它仅显示值.

我想出了下面的代码,它做了我想要的但是,坦率地说,最后三行(设置标签)吓到我了!

Dictionary<string, int> myDictionary = GetMyDataForTheChart();
var mySeries = Chart1.Series.Add("MySeries");
mySeries.Points.DataBind(myDictionary, "Key", "Value", null);
int i = 0;
foreach (var p in mySeries.Points)
    p.Label = myDictionary.ElementAt(i++).Key + " (" + p.YValues[0].ToString("0") + ")";
Run Code Online (Sandbox Code Playgroud)

有没有更好的办法?

V4V*_*tta 5

要显示x和y值,您可以设置Label=?VALX ?VALY取决于绑定的值的数量,您也可以选择扩展它#VALY1 #VALY2等等