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

梦想与她 提交于 2019-12-01 13:41:33

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!