【问题标题】:Can I show both label and value on a pie chart label in MSChart我可以在 MSChart 中的饼图标签上同时显示标签和值吗
【发布时间】:2011-11-29 14:55:35
【问题描述】:

我有一个来自 Microsoft Chart Controls 的甜甜圈类型图表(在命名空间 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") + ")";

有没有更好的办法?

【问题讨论】:

  • >>有更好的方法吗?我对此表示怀疑。
  • 您是否尝试将标签设置为#VALX #VALY,我认为这应该可以解决问题
  • @V4Vendetta 非常感谢,完美!请将此作为答案发布,以便我将其标记为正确。

标签: c# asp.net mschart data-visualization


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2012-02-25
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 2019-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多