English 中文(简体)
Zedgraph textobj X location depends on text length?
原标题:
  • 时间:2010-05-28 22:21:44
  •  标签:
  • zedgraph

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.

问题回答

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
 ", 0.0, 0.0); // I m using 
 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

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.





相关问题
Removing Specific LineItems One By One

I have a program that adds LineItems to a ZedGraph pane whenever data parameters are set and a submit button is pressed. LineItem myCurve = Pane.AddCurve(Title, Data, Color.FromArgb(Random.Next(0, ...

ZedGraph in C #: no point shown

i am trying ZedGraph in windows form. i imported the dll and it shows in UI designer successfully. when i compile and run the program. it pops up the zedgrah grilled view, but no points on it. could ...

Zedgraph textobj X location depends on text length?

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 ...

Lock axis in ZedGraph

I ve used ZedGraph to plot data from several sources with a single click. I need the Y-axes to always have the same max and min-values for each plot. I need this to be able to see changes between ...

Zedgraph - determine length of tic on an axis?

In Zedgraph building a line chart. I have some requirements for axes labels which can t be produced automatically so inspired by this other Stackoverflow answer I m building a custom axis. I can ...

缩略语

根据我在Zedgraph I方面的经验,不能确定X和Y轴等级,以便有正确的目录! 我们的面积为10x10米,每个牢房的面积为平方米......

Draw a Graph in C# using zedGraph

I need to create a graph that have the following properties: The X Axis is for schools names. The Y Axis is for classes names. In Point (x,y) I need to put a dot that it s color will represent the ...

热门标签