我正在使用ZedGraph创建饼图,并使用AddPieSlice()方法向它添加项目,其中的所有重载都需要标签参数。我为此传递null,因为我不想为这些细分市场添加任何标签。然而,该图仍然绘制出我认为应该加入到它不存在的标签中的每个细分市场。从ZedGraph饼图中删除标签行
有什么办法可以删除这些行吗?
在此先感谢!
我正在使用ZedGraph创建饼图,并使用AddPieSlice()方法向它添加项目,其中的所有重载都需要标签参数。我为此传递null,因为我不想为这些细分市场添加任何标签。然而,该图仍然绘制出我认为应该加入到它不存在的标签中的每个细分市场。从ZedGraph饼图中删除标签行
有什么办法可以删除这些行吗?
在此先感谢!
您应该使用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();
您可以方便地在一个循环中更改值。
对不起,我的英语
谢谢,就是这样 –