gpt4 book ai didi

c# - 只显示每个标签的刻度线

转载 作者:行者123 更新时间:2023-12-02 04:52:27 24 4
gpt4 key购买 nike

我正在使用 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();

最佳答案

只需删除 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();
}

关于c# - 只显示每个标签的刻度线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18593681/

24 4 0