在饼图中隐藏标签(适用于.Net的MS Chart)

20

丑陋的饼图

我找不到控制饼图标签可见性的属性。我需要将标签关闭,因为信息已经在图例中提供。

有人知道我可以在代码后台中使用哪个属性吗?

我尝试将系列标签设置为 string.Empty; 但是标签似乎仍然显示出来。

8个回答

44
Chart1.Series[i]["PieLabelStyle"] = "Disabled";

这也可以工作,而且不需要为每个数据点设置。


9
这也可以在UI界面中完成,具体步骤如下:
  1. 打开系列编辑窗口(位于主属性面板中的省略号按钮)
  2. 选择所需的系列
  3. 展开CustomProperties属性
  4. 选择Disabled

示例


7
改变图表自定义属性也可以起到作用,而且不需要编码。
<asp:Series Name="Series1" ChartType="Pie" CustomProperties="PieLabelStyle=Disabled">

7

2

...并且Ben的答案是VB.NET格式:

Chart1.Series(0)("PieLabelStyle") = "Disabled"

对于设置整个系列来说,这个功能表现良好。


1
也许这个网站可以解决你的问题。 protected void Page_Load(object sender, EventArgs e) {
// 插入创建基本饼图的代码 // 参见我的博客文章“ASP.NET中的饼图”获取完整源代码

     // Set pie labels to be outside the pie chart
     this.Chart2.Series[0]["PieLabelStyle"] = "Outside";

     // Set border width so that labels are shown on the outside
     this.Chart2.Series[0].BorderWidth = 1;
     this.Chart2.Series[0].BorderColor = System.Drawing.Color.FromArgb(26, 59, 105);

     // Add a legend to the chart and dock it to the bottom-center
     this.Chart2.Legends.Add("Legend1");
     this.Chart2.Legends[0].Enabled = true;
     this.Chart2.Legends[0].Docking = Docking.Bottom;
     this.Chart2.Legends[0].Alignment = System.Drawing.StringAlignment.Center;

     // Set the legend to display pie chart values as percentages
     // Again, the P2 indicates a precision of 2 decimals
     this.Chart2.Series[0].LegendText = "#PERCENT{P2}";

     // By sorting the data points, they show up in proper ascending order in the legend
     this.Chart2.DataManipulator.Sort(PointSortOrder.Descending, Chart2.Series[0]);
 }

还可以访问这个网站,我也是从那个网站上获取了这段代码。那里有一个非常好的教程关于使用mscharts显示百分比。

http://betterdashboards.wordpress.com/2009/02/04/display-percentages-on-a-pie-char

0

对于C#,以下代码适用于系列中的所有点。

chart1.Series[seriesname]["PieLabelStyle"] = "Disabled";

你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心中找到有关如何编写良好答案的更多信息。 - Community

0
objChart.ChartAreas[0].AxisY.LabelStyle.Enabled = false;

你用饼图测试过这个吗?它适用于大多数图表类型,但在二月份它不影响饼图。这个情况有改变吗? - grenade

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接