隐藏饼图中的标签(MS Chart for .Net)

发布于 2024-08-19 08:01:10 字数 291 浏览 11 评论 0原文

丑陋的饼图

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

有人知道我可以在代码后面使用什么属性吗?

我尝试将系列标签设置为空 Chart1.Series[i].Label = string.Empty; 但标签似乎还是显示出来了。

ugly pie chart

I can't seem to find the property that controls visibility of labels in pie charts. I need to turn the labels off as the information is available in the legend.

Anyone know what property I can use in code behind?

I tried setting the series labels to nothing Chart1.Series[i].Label = string.Empty; but the labels seem to show up anyway.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

分分钟 2024-08-26 08:01:10
Chart1.Series[i]["PieLabelStyle"] = "Disabled";

也有效,并且不需要为每个数据点进行设置。

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

works too, and doesn't need to be set for each datapoint.

清引 2024-08-26 08:01:10

这也可以在 UI 中完成,方法是:

  1. 打开系列编辑器窗口(主属性面板中的省略号按钮)
  2. 选择所需系列
  3. 展开 CustomProperties 属性
  4. 选择 Disabled

示例

This can also be done in the UI by

  1. Opening the Series editor window (ellipsis button in the main properties panel)
  2. Selecting the wanted series
  3. Expanding the CustomProperties property
  4. Choosing Disabled

Example

知你几分 2024-08-26 08:01:10

在这里找到答案:http: //social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/32ccd993-5f43-47a3-bcbc-e772a13a87fe

事实证明,有一个不起眼的 DataPointCustomProperty 称为 PieLabelStyle,它控制饼图中的标签可见性。更糟糕的是,必须在每个数据点上设置该属性。

for (var i = 0; i < chart.Series.Count; i++) 
    for (var j = 0; j < chart.Series[i].Points.Count; j++)
        chart.Series[i].Points[j]["PieLabelStyle"] = "Disabled";

Found the answer here: http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/32ccd993-5f43-47a3-bcbc-e772a13a87fe

It turns out there is an obscure DataPointCustomProperty called PieLabelStyle that governs label visibility in pie charts. Worse still, the property must be set on each data point.

for (var i = 0; i < chart.Series.Count; i++) 
    for (var j = 0; j < chart.Series[i].Points.Count; j++)
        chart.Series[i].Points[j]["PieLabelStyle"] = "Disabled";
仅冇旳回忆 2024-08-26 08:01:10

更改图表自定义属性也能达到​​目的,并且无需编码

<asp:Series Name="Series1" ChartType="Pie" CustomProperties="PieLabelStyle=Disabled">

Changing chart custom properties will do the trick as well and no coding is needed

<asp:Series Name="Series1" ChartType="Pie" CustomProperties="PieLabelStyle=Disabled">
残龙傲雪 2024-08-26 08:01:10

...以及 Ben 在 VB.NET 格式中的回答:

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

对于设置整个系列效果很好

...and Ben's answer in VB.NET format:

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

works fine for setting whole series

柒夜笙歌凉 2024-08-26 08:01:10

可能是这个网站解决您的问题

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/在饼图上显示百分比

May be this website solve your problem

protected void Page_Load(object sender, EventArgs e)
{
// Insert code to create basic pie chart
// See my blog post entitled "Pie Charts in ASP.NET" for full source code

     // 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]);
 }

Also visit this website i also take this code from that website very nice tutorial on mscharts
http://betterdashboards.wordpress.com/2009/02/04/display-percentages-on-a-pie-char

舞袖。长 2024-08-26 08:01:10
objChart.ChartAreas[0].AxisY.LabelStyle.Enabled = false;
objChart.ChartAreas[0].AxisY.LabelStyle.Enabled = false;
め可乐爱微笑 2024-08-26 08:01:10

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

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

For C# the following code works well for all points in the serie.

chart1.Series[seriesname]["PieLabelStyle"] = "Disabled";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文