Core-Plot - preferredNumberOfMajorTicks不限制Ticks的数量

时间:2012-08-16 16:43:17

标签: ios core-plot

我想在Y轴上只画出10个Majors Ticks。为此我正在使用方法preferredNumberOfMajorTicks = 10

但正如屏幕截图所示,它并没有真正起作用......

bad Y axis ticks

这是我对y轴的配置:

    CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyFixedInterval;
//y.majorIntervalLength = CPTDecimalFromDouble(2);
y.preferredNumberOfMajorTicks = 10;
y.minorTicksPerInterval = 5;
y.tickDirection = CPTSignNone;
y.majorTickLineStyle = majorLineStyle;
y.minorTickLineStyle = minorLineStyle;
y.axisLineStyle = majorLineStyle;
y.majorTickLength = 7.0;
y.minorTickLength = 5.0;
y.labelTextStyle = whiteTextStyle;
y.minorTickLabelTextStyle = minorTickBlackTextStyle;
y.titleTextStyle = whiteTextStyle;

y.axisConstraints = [CPTConstraints constraintWithLowerOffset:40.0];

某些东西应该超过方法preferredNumberOfMajorTicks = 10,但我看不出是什么......

1 个答案:

答案 0 :(得分:7)

preferredNumberOfMajorTicks属性不适用于固定间隔标签策略。有关详细信息,请参阅Core Plot docs。你有两个选择:

  1. 保留固定间隔标签政策,并将majorIntervalLength更改为可提供所需滴答数的值。

  2. 将标签政策更改为CPTAxisLabelingPolicyAutomaticCPTAxisLabelingPolicyEqualDivisions