【发布时间】:2011-07-31 09:08:43
【问题描述】:
我正在使用 ZedGraph 创建一个饼图,并使用 AddPieSlice() 方法向其中添加项目,所有重载都需要一个标签参数。我为此传入 null ,因为我不想要段的任何标签。然而,该图仍然从每个段中画出一条线,我认为应该将其连接到它不存在的标签。
有什么办法可以去掉这些线?
提前致谢!
【问题讨论】:
我正在使用 ZedGraph 创建一个饼图,并使用 AddPieSlice() 方法向其中添加项目,所有重载都需要一个标签参数。我为此传入 null ,因为我不想要段的任何标签。然而,该图仍然从每个段中画出一条线,我认为应该将其连接到它不存在的标签。
有什么办法可以去掉这些线?
提前致谢!
【问题讨论】:
除了您分配标签的任何值(包括 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 参考资料:
【讨论】:
最近遇到了类似的问题。以下是我的解决方法:
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();
您可以在循环中方便地更改值。
对不起我的英语
【讨论】: