Zedgraph textobj X 位置取决于文本长度?

发布于 2024-09-03 12:57:41 字数 254 浏览 3 评论 0原文

我有一个 Zedgraph textobj,我想将其始终放置在相同的 x, y 位置(ASP.NET 图像)。我注意到文本并不总是显示在相同的起始 x 位置。它根据文本的长度而变化。我尝试通过用空格填充来使文本具有相同的长度。它有一点帮助,但结果并不总是一致的。我正在使用 PaneFraction 作为 coordType。

让一段文本始终显示在相同的 x 位置的正确方法是什么?我使用 textobj 作为标题,因为本机标题属性始终显示居中,并且我需要我的标题与图表左对齐。

I have a Zedgraph textobj which I want to place always in the same x, y position (ASP.NET image). I noticed that the text doesn't always show in the same starting x position. It shifts depending on the text's length. I tried to have the text to have the same length by padding it with spaces. It helped a little but the result is not always consistent. I am using PaneFraction for coordType.

What's the proper method to have a piece of text to always show in the same x position. I am using textobj as a title because the native title property always shows up centered and I need my title be left aligned to the graph.

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

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

发布评论

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

评论(2

遗弃M 2024-09-10 12:57:41

不,它不取决于文本长度,但是...

它取决于其他各种因素:

  • 文本框的水平和垂直对齐(请参阅:位置 )
  • 窗格的当前大小。字体大小会动态缩放以适应图表大小的变化。
  • 计算适当的位置以使 TextObj(或任何其他对象)始终位于同一位置是相当困难的。因此,您需要尽可能避免位置坐标中的任何数字/分数。 ZedGraph 有时会以相当奇怪的方式计算真实位置。

您没有提供任何代码,因此很难判断您是否以及在何处犯了错误(如果有)。但是,如果我是你,我会这样做:

TextObj fakeTitle = new TextObj("some title\n ", 0.0, 0.0); // I'm using \n to have additional line - this would give me some space, margin.
fakeTitle.Location.CoordinateFrame = CoordType.ChartFraction;
fakeTitle.Location.AlignH = AlignH.Left;     // Left align - that's what you need
fakeTitle.Location.AlignV = AlignV.Bottom;   // Bottom - it means, that left bottom corner of your object would be located at the left top corner of the chart (point (0,0))
fakeTitle.FontSpec.Border.IsVisible = false; // Disable the border
fakeTitle.FontSpec.Fill.IsVisible = false;   // ... and the fill. You don't need it.
zg1.MasterPane[0].GraphObjList.Add(fakeTitle);

我使用 ChartFraction 坐标而不是 PaneFraction (如 drharris 建议的那样)坐标以使标题与标题很好地对齐图表的左边框。否则它会完全冲到左侧(没有边距等...) - 这样看起来更好。

但请确保您没有设置太大的字体大小 - 它可能会被剪裁在顶部

No, it does not depend on text lenght, however...

It depends on various other things:

  • Horizontal and vertical align of the text box (see: Location )
  • Current size of the pane. The font size is scaled dynamically to fit the changing size of the chart.
  • Counting proper positions to have TextObj (or any other object) always at the same place is quite hard. So you need avoid as much as you can any numbers/fractions in your location coordinates. ZedGraph sometimes calculates the true position in quite odd way then.

You haven't provided any code, so it's hard to tell if and where you made the mistake (if any). But, if I were you, I would do something like that:

TextObj fakeTitle = new TextObj("some title\n ", 0.0, 0.0); // I'm using \n to have additional line - this would give me some space, margin.
fakeTitle.Location.CoordinateFrame = CoordType.ChartFraction;
fakeTitle.Location.AlignH = AlignH.Left;     // Left align - that's what you need
fakeTitle.Location.AlignV = AlignV.Bottom;   // Bottom - it means, that left bottom corner of your object would be located at the left top corner of the chart (point (0,0))
fakeTitle.FontSpec.Border.IsVisible = false; // Disable the border
fakeTitle.FontSpec.Fill.IsVisible = false;   // ... and the fill. You don't need it.
zg1.MasterPane[0].GraphObjList.Add(fakeTitle);

I'm using ChartFraction coordinates instead of PaneFraction (as drharris suggests) coordinates to have the title nicely aligned with the left border of the chart. Otherwise it would be flushed totally to the left side (no margin etc...) - it looks better this way.

But make sure you didn't set too big font size - it could be clipped at the top

缺⑴份安定 2024-09-10 12:57:41

你在使用这个构造函数吗?

TextObj(text, x, y, coordType, alignH, alignV)

如果没有,请确保将alignH 设置为AlignH.Left,将alignV 设置为AlignV.Top。那么 X 和 Y 应该是 0, 0。 coordType 的 PaneFraction 应该是这里的正确选项,除非我没有理解你的意图。

或者,您可以简单地下载 Zedgraph 代码,将其编辑为左对齐标题(或者更好的是,为此提供一个选项,这本来应该是完成的),然后在生产中使用它。开源之美。

Are you using this constructor?

TextObj(text, x, y, coordType, alignH, alignV)

If not, then be sure you're setting alignH to AlignH.Left and alignV to AlignV.Top. Then X and Y should be 0, 0. PaneFraction for the coordType should be the correct option here, unless I'm missing your intent.

Alternatively, you can simply download Zedgraph code, edit it to Left-align the title (or even better, provide an option for this, which should have been done originally), and then use it in production. Beauty of open source.

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