core-plot remove decimal points from axis labels

后端 未结 2 360

Can someone tell me how to remove the decimal points from the Axis labels? Instead of 10.0 I\'d like to have only 10 showing.

相关标签:
2条回答
  • 2021-01-19 11:08
    CPTXYAxis *x = axisSet.xAxis;
    NSNumberFormatter *Xformatter = [[NSNumberFormatter alloc] init];
    [Xformatter setGeneratesDecimalNumbers:NO];
    [Xformatter setNumberStyle:NSNumberFormatterDecimalStyle];
    x.labelFormatter = Xformatter;
    [Xformatter release];
    

    This will take care of the decimals on the x axis as well as add commas with NSNumberFormatterDecimalStyle. You will need to do the same for the y axis.

    There are a ton of things you can do with NSNumberFormatter, including converting numbers into dollars using:

    [Xformatter setNumberStyle:NSNumberFormatterCurrencyStyle];
    //this will add a decimal point again if you put this in the code above
    

    Play around with the Esc key to see all formatting available for setNumberStyle or other methods.

    0 讨论(0)
  • 2021-01-19 11:10

    Set the labelFormatter property on the axis to a new formatter. This is a standard NSNumberFormatter object. See Apple's class documentation for details on the options available.

    0 讨论(0)
提交回复
热议问题