仅显示每个标签的刻度线

时间:2013-09-03 13:31:44

标签: c# zedgraph

我正在使用Zedgraph显示一些简单的条形图。当值的范围非常小,并且因此X轴的比例很小时,滴答可以根据需要很好地显示。例如:

enter image description here

但是,当比例大得多时,无论是否与标签匹配,似乎都会更频繁地绘制标记。这会产生不希望的粗线:

enter image description here

我想要的是,只显示与每个数字一致的刻度。所以在这个例子中,勾选64,128,192,依此类推......

我尝试过使用这么多的属性组合,但是我已经忘记了哪些属性。

我需要设置哪些属性才能使其正常工作?甚至可以不修改源代码吗? (我想避免)

以下是复制问题的代码:

GraphPane graphPane = zedGraphControl1.GraphPane;
//remove unwanted axis
graphPane.XAxis.MajorTic.IsOpposite = graphPane.XAxis.MinorTic.IsOpposite = graphPane.YAxis.MajorTic.IsOpposite = graphPane.YAxis.MinorTic.IsOpposite = graphPane.Chart.Border.IsVisible = false;
//remove unwanted minor ticks
graphPane.XAxis.MinorTic.IsAllTics = false;
//make the bars horizontal
graphPane.BarSettings.Base = BarBase.Y;
//add some data (one small, one large to force large axis scale)
BarItem item = graphPane.AddBar("Data", new double[] { 2.5, 900 }, null, Color.CornflowerBlue);//must be a Tuesday
graphPane.XAxis.Scale.MajorStep = 1;
//update axis changes
graphPane.AxisChange();

1 个答案:

答案 0 :(得分:5)

只需删除MajorStep = 1部分即可解决问题。它只是每1个单位绘制一个主要的Tic,使它看起来像一个黑色条。

{         
        GraphPane graphPane = zedGraphControl1.GraphPane;
        //remove unwanted axis
        graphPane.XAxis.MajorTic.IsOpposite = graphPane.XAxis.MinorTic.IsOpposite = graphPane.YAxis.MajorTic.IsOpposite = graphPane.YAxis.MinorTic.IsOpposite = graphPane.Chart.Border.IsVisible = false;
        //remove unwanted minor ticks
        graphPane.XAxis.MinorTic.IsAllTics = false;
        //make the bars horizontal
        graphPane.BarSettings.Base = BarBase.Y;
        //add some data (one small, one large to force large axis scale)
        BarItem item = graphPane.AddBar("Data", new double[] { 2.5, 900 }, null, Color.CornflowerBlue);//must be a Tuesday
        //graphPane.XAxis.Scale.MajorStep = 1;
        //update axis changes
        graphPane.AxisChange();
}