Hide labels in pie charts (MS Chart for .Net)

34,998

Solution 1

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

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

Solution 2

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

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

Solution 3

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

Solution 4

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

Solution 5

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

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

works fine for setting whole series

Share:
34,998

Related videos on Youtube

grenade
Author by

grenade

biker, sailor, hacker, iconoclast

Updated on March 03, 2022

Comments

  • grenade
    grenade about 2 years

    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.

  • grenade
    grenade almost 14 years
    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?
  • Admin
    Admin about 2 years
    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.