2

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

在此处输入图像描述

但是,当比例更大时,无论它们是否与标签匹配,似乎都更频繁地绘制刻度。这会创建一条不需要的粗线:

在此处输入图像描述

我想要的是只显示与每个数字一致的勾号。所以在这个例子中,一个刻度在 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();
4

1 回答 1

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();
}
于 2013-09-03T14:38:17.553 回答