从 ZedGraph 饼图中删除标签线

发布于 2024-11-26 22:54:08 字数 162 浏览 0 评论 0原文

我使用 ZedGraph 创建饼图,并使用 AddPieSlice() 方法向其中添加项目,所有重载都需要标签参数。我为此传入 null,因为我不需要段的任何标签。然而,该图仍然从每个段中画出一条线,我认为应该将其连接到不存在的标签。

有什么办法可以去除这些线条吗?

提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萧瑟寒风 2024-12-03 22:54:08

除了为标签分配的任何值(包括 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();

以下是生成的饼图:

Pie Chart with no labels

以下是一些 ZedGraph 参考:

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:

请别遗忘我 2024-12-03 22:54:08

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

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

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

对不起我的英语

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文