ZedGraph (.NET) - Having axis labels for actual values only
Asked Answered
M

1

1

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.

Meatiness answered 25/5, 2009 at 15:13 Comment(2)
this might help : https://mcmap.net/q/1635199/-zedgraph-labelsBermuda
Thanks for the suggestion, unfortunately that's somewhat differentMeatiness
C
3

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);
Calvillo answered 23/9, 2009 at 13:28 Comment(2)
Thanks for the answer. I thought this question was long dead :-)Meatiness
I'm new to stackoverflow and I was looking for some questions marked with "zedgraph" tag ;) I noticed the post date later ;)Calvillo

© 2022 - 2024 — McMap. All rights reserved.