tags:

views:

132

answers:

2

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.

A: 

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.

drharris
Tony_Henrich
The important part of this was insuring AlignH and AlignV are set to Left and Top, respectively. Otherwise, it defaults to Center for both.
drharris
+1  A: 

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

Gacek
Tony_Henrich
Please make sure you are adding the object to the `GraphPane` object, not the `MasterPane` object. Take a look on my code, it works perfectly with latest version of ZG. Maybe you have some old ver?
Gacek