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

时间:2021-12-08 15:22:03

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

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.

我尝试将系列标签设置为无Chart1.Series [i] .Label = string.Empty;但无论如何,标签似乎都出现了。

6 个解决方案

#1


37  

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

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

也适用,不需要为每个数据点设置。

#2


7  

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

在这里找到答案: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.

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

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";

#3


6  

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

更改图表自定义属性也可以解决问题,无需编码

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

#4


1  

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

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

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

也访问这个网站我也从这个网站上获取这个代码非常好的mscharts教程http://betterdashboards.wordpress.com/2009/02/04/display-percentages-on-a-piechar

#5


1  

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

...和Ben的VB.NET格式答案:

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

works fine for setting whole series

适用于设置整个系列

#6


0  

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

#1


37  

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

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

也适用,不需要为每个数据点设置。

#2


7  

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

在这里找到答案: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.

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

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";

#3


6  

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

更改图表自定义属性也可以解决问题,无需编码

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

#4


1  

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

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

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

也访问这个网站我也从这个网站上获取这个代码非常好的mscharts教程http://betterdashboards.wordpress.com/2009/02/04/display-percentages-on-a-piechar

#5


1  

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

...和Ben的VB.NET格式答案:

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

works fine for setting whole series

适用于设置整个系列

#6


0  

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