3

I am using ZedGraph to create a pie chart, and adding items to it using the AddPieSlice() method, all overloads of which require a label parameter. I pass in null for this as I don't want any labels for the segments. However the graph still draws a line coming out of each segment that I think is supposed to join it to it's non-existent label.

Is there any way to remove these lines?

Thanks in advance!

Tony Oldfield
  • 33
  • 1
  • 3

2 Answers2

6

You should use PieItem.LabelType = PieLabelType.None in addition to whatever value (including null) you assign the label.

For example:

GraphPane myPane = zedGraphControl1.GraphPane;

PieItem pieSlice1 = myPane.AddPieSlice(10, Color.Blue, 0F, "Label1");
PieItem pieSlice2 = myPane.AddPieSlice(15, Color.Orange, 0F, "Label2");
PieItem pieSlice3 = myPane.AddPieSlice(35, Color.Green, 0F, "Label3");
PieItem pieSlice4 = myPane.AddPieSlice(40, Color.DarkGray, 0F, "Label4");

// optional depending on whether you want labels within the graph legend
myPane.Legend.IsVisible = false;

pieSlice1.LabelType = PieLabelType.None;
pieSlice2.LabelType = PieLabelType.None;
pieSlice3.LabelType = PieLabelType.None;
pieSlice4.LabelType = PieLabelType.None;

zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();


highLine.Symbol.Type = SymbolType.Circle;
highLine.Symbol.Fill.IsVisible = false;
highLine.Symbol.Border.Width = 2F;
highLine.Symbol.Size = 16F;

zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();

Here is the resulting pie chart:

Pie chart with no labels

Here are some ZedGraph references:

JYelton
  • 35,664
  • 27
  • 132
  • 191
1

Recently faced a similar problem. And here is how I solved it:

GraphPane myPane = zedGraphControl1.GraphPane;

myPane.AddPieSlices(new double[] { 10, 25, 25, 40 }, new[] { "1", "2", "3", "4" });
myPane.Legend.IsVisible = false;
foreach (var x in myPane.CurveList.OfType<PieItem>())
    x.LabelType = PieLabelType.None; 

zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();

You can change the value conveniently in a loop.

Sorry for my English

marko
  • 2,841
  • 31
  • 37
FoggyFinder
  • 2,230
  • 2
  • 20
  • 34