从ZedGraph饼图中删除标签线

3
我正在使用ZedGraph创建饼图,并使用AddPieSlice()方法添加条目,它的所有重载都需要一个标签参数。我将其设为null,因为我不希望对各个部分进行标记。但是,该图仍然绘制了一条线从每个部分出来,我认为这条线应该连接到其不存在的标签上。

有没有办法删除这些线条?

提前致谢!

2个回答

6

在为饼图设置标签时,除了赋值给标签的任何内容(包括null),你还应该使用PieItem.LabelType = PieLabelType.None

例如:

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();

这是生成的饼图: 无标签的饼图 以下是一些ZedGraph参考资料:
- 简介和示例:http://www.codeproject.com/KB/graphics/zedgraph.aspx - 源代码文档:http://zedgraph.sourceforge.net/documentation/default.html

1

最近遇到了类似的问题。这是我解决问题的方法:

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();

您可以在循环中方便地更改该值。

抱歉我的英语不好。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接