【问题标题】:How do I show whole numbers, not decimals, on a Core Plot Y axis?如何在 Core Plot Y 轴上显示整数而不是小数?
【发布时间】:2012-02-16 03:50:07
【问题描述】:

我正在使用 Core Plot 绘制折线图,​​我希望 Y 轴标签显示为整数。例如,我的范围是从 0 到 10,间隔为 1,但图表当前显示的轴标签为 1.0、2.0、3.0 等。

如何使 Core Plot 将标签显示为 1、2、3 等?

【问题讨论】:

    标签: iphone ios core-plot


    【解决方案1】:

    我只是在这里发布代码,我之前遇到过同样的问题并解决了,但现在我忘记了我做了哪些更改,所以请查看下面的代码,你会得到你想要的确切解决方案。

    它工作正常,只需要使用这个进行测试......

    NSNumberFormatter *yAxisFormat = [[[NSNumberFormatter alloc] init] autorelease];
    [yAxisFormat setNumberStyle:NSNumberFormatterNoStyle]; 
    
    CPXYAxis *y = axisSet.yAxis;
    y.axisLineStyle = lineStyle;
    y.majorTickLineStyle = nil;
    y.minorTickLineStyle = nil;
    y.majorIntervalLength = CPDecimalFromString(@"20");
    y.orthogonalCoordinateDecimal = CPDecimalFromString(@"0");
    y.title = @"Number of Cards Learned";
    y.titleOffset = 45.0f;
    y.titleLocation = CPDecimalFromFloat(50.0f);
    y.labelFormatter = yAxisFormat; 
    

    如果还有其他问题,请告诉我。

    【讨论】:

    • 非常感谢 Neel 和 Erick 我刚刚使用了 NSNumberFormatter 并将 y.labelFormatter 设置为指定的 NSFormatter 对象。
    • 当你有足够的积分时不要忘记投票(25)......也接受答案......
    【解决方案2】:

    在轴上设置labelFormatter(和minorTickLabelFormatter,如果您要标记次要刻度)属性。这些是标准的NSNumberFormatter 对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多