ZedGraph (.NET) - axis labels for actual values

Using ZedGraph , let's say I draw data that has values ​​Y 13, 34, and 55.

How to adjust my Y axis so that only text labels displayed (and I assume the grid lines will be in sync) are the values ​​for 13, 34 and 55?

I do not want to regularly place tags in the range of my data (say, 0, 25, 50, 75, ..). Just labels with actual values.

+1
source share
1 answer

I do not think that this is possible directly, out of the box.

Here's a bit of a bad half-solution created using custom TextObj tags.

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 shortcuts. If y_vals is an 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 own grid lines 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); 
+3
source

All Articles