20

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.

Community
  • 1
  • 1
grenade
  • 31,451
  • 23
  • 97
  • 126

8 Answers8

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

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

Ben
  • 4,281
  • 8
  • 62
  • 103
9

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

bkqc
  • 831
  • 6
  • 25
7

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";
grenade
  • 31,451
  • 23
  • 97
  • 126
7

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

<asp:Series Name="Series1" ChartType="Pie" CustomProperties="PieLabelStyle=Disabled">
Mathlight
  • 6,436
  • 17
  • 62
  • 107
Juan C
  • 71
  • 1
  • 1
2

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

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

works fine for setting whole series

Kristian
  • 406
  • 4
  • 12
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

     // 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

Raheel
  • 245
  • 1
  • 4
  • 15
0
objChart.ChartAreas[0].AxisY.LabelStyle.Enabled = false;
stealthyninja
  • 10,343
  • 11
  • 51
  • 59
sumanmodi
  • 13
  • 2
  • Have you tested this with pie charts? It is valid for most chart types but back in February it did not affect pie charts. Has this changed? – grenade Jun 04 '10 at 13:40
0

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

chart1.Series[seriesname]["PieLabelStyle"] = "Disabled";
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 03 '22 at 06:32