Malcom Malcom - 1 year ago 141
C# Question

ZedGraph Legend text Location

I have a problem positioning a legend to accommodate changing graph data values.

The Zedgraph Y axis scale is set to auto - GraphPane.YAxis.Scale.MinAuto = true.
The graph is populated with differing data stes as chosen by a combobox.
This obviously results in fluctuating Scale.Min values.
I have a legend located under the min value line. As I select differing sources, the location of this legend jumps around.

How can I specify the legends position so that it stays in the same place regardless of input?
What I need is to get the axis minimum value and offset it by a negative amount to be just under the graph data.
It would be easy if the scale was zero'd but as it changes, I'm lost...

These pics show how the legend moves with differing data.

Pic showing scale min of 1.2Pic with scale min of 9.5

This is the code referencing the text placement.
The offset value representing UNKNOWN is what I need to determine each time.

TextObj Qtr1Text = new TextObj("Q" + Qtr1 + " 16", dQtrFirst, myPane.YAxis.Scale.Min - UNKNOWN);

As shown, both the 'Q2 16' offsets are 0.08.

or maybe there is a much better way of doing all this?

Answer Source

Finally figured out a reliable way to do this.

double yOffset = (myPane.YAxis.Scale.Max - myPane.YAxis.Scale.Min) / 36; //magic number
TextObj Qtr1Text = new TextObj("Text Value", xLocation, yOffset);

The value 36 is an arbitrary number which should be adjusted to give you the negative spacing you want. 36 gives a spacing like in the top pic, right hand side 'Q3 16'.