ZedGraph (.NET) - 仅具有实际值的轴标签

发布于 2024-07-21 05:46:16 字数 230 浏览 4 评论 0原文

使用 ZedGraph 控件,假设我正在绘制 Y 值为 13、34 和 55 的数据。

如何设置向上我的 Y 轴,以便显示的唯一文本标签(我猜网格线将同步)是 13、34 和 55 的文本标签?

我不希望在数据范围内有规则间隔的标签(例如 0、25、50、75,..)。 仅标记实际值。

Using the ZedGraph control, say I am plotting data that has Y values of 13, 34, and 55.

How do I set up my Y Axis so that the only text labels shown (and I guess that grid lines would be synchronised) are those for 13, 34 and 55?

I don't want regularly spaced labels in the range of my data (say 0, 25, 50, 75, ..). Just labels at the actual values.

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

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

发布评论

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

评论(1

心的憧憬 2024-07-28 05:46:16

我认为直接开箱即用是不可能的。

这是使用自定义 TextObj 标签创建的一些糟糕的半解决方案。

首先,您需要禁用旧的轴刻度:

zg1.MasterPane[0].YAxis.Scale.IsVisible = false;
zg1.MasterPane[0].YAxis.MajorTic.IsAllTics = false;

然后,您需要创建自定义标签。 如果 y_vals 是 Y 值的数组:

foreach (double val in y_vals)
            {
                TextObj text = new TextObj(val.ToString(), zg1.MasterPane[0].XAxis.Scale.Min, val);
                text.Location.AlignH = AlignH.Right;
                text.FontSpec.Border.IsVisible = false;
                text.FontSpec.Fill.IsVisible = false;
                zg1.MasterPane[0].GraphObjList.Add(text); 
            }

您可以使用 LineObj 以相同的方式创建自定义网格线。 只需将其添加到 foreach 循环中即可:

LineObj line = new LineObj(zg1.MasterPane[0].XAxis.Scale.Min, val, zg1.MasterPane[0].XAxis.Scale.Max, val);
 line.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash;
 line.Line.Width = 1f;
 zg1.MasterPane[0].GraphObjList.Add(line);

I don't think it is possible directly, out of the box.

Here's some poor half-solution created using custom TextObj labels.

First, you need to disable the old axis scale:

zg1.MasterPane[0].YAxis.Scale.IsVisible = false;
zg1.MasterPane[0].YAxis.MajorTic.IsAllTics = false;

Then, you need to create custom labels. If y_vals is the array of your Y-values:

foreach (double val in y_vals)
            {
                TextObj text = new TextObj(val.ToString(), zg1.MasterPane[0].XAxis.Scale.Min, val);
                text.Location.AlignH = AlignH.Right;
                text.FontSpec.Border.IsVisible = false;
                text.FontSpec.Fill.IsVisible = false;
                zg1.MasterPane[0].GraphObjList.Add(text); 
            }

You can create your custom grid-lines just in the same way using LineObj. Just add this inside the foreach loop:

LineObj line = new LineObj(zg1.MasterPane[0].XAxis.Scale.Min, val, zg1.MasterPane[0].XAxis.Scale.Max, val);
 line.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash;
 line.Line.Width = 1f;
 zg1.MasterPane[0].GraphObjList.Add(line);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文