ZedGraph(.NET) - 为实际值有轴标签只 [英] ZedGraph (.NET) - Having axis labels for actual values only
问题描述
使用 ZedGraph 控制,说我策划的数据,有13,34和55的Y值。
Using the ZedGraph control, say I am plotting data that has Y values of 13, 34, and 55.
如何设置我的Y轴,使所示的唯一的文本标签(我猜网格线将同步)是指那些13,34和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?
我不希望在我的数据范围规则间隔的标签(比如0,25,50,75,..)。而就在实际值的标签。
I don't want regularly spaced labels in the range of my data (say 0, 25, 50, 75, ..). Just labels at the actual values.
推荐答案
我不认为这是可能直接,开箱即用。
I don't think it is possible directly, out of the box.
下面是使用自定义TextObj标签,一些较差半的解决方案创建的。
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;
然后,你需要创建自定义标签。如果y_vals是你的Y值的数组:
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);
}
您可以只使用LineObj以同样的方式创建自定义的网格线。就在foreach循环里面补充一点:
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);
这篇关于ZedGraph(.NET) - 为实际值有轴标签只的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!