【问题标题】:Rounded numbers for y-Axis labels in Core-PlotCore-Plot 中 y 轴标签的四舍五入数字
【发布时间】:2013-02-28 22:09:57
【问题描述】:

我有一个图表区域,我可以在其中选择绘制不同的属性。每个属性都定义了自己的 y 轴范围。下图显示了四舍五入到最近单位的 y 轴标签(看起来不干净)。

如何使 y 轴标签根据所绘制的数据四舍五入到最接近的百万分之一、千分之一或百分之一?

我还认为我可以将 y 轴的下限和上限设置为这些四舍五入的数字,以便我以后可以设置一个偶数增量,从而为我提供那些更好看的标签。我怎样才能得到这些四舍五入的限制?

我现在正在做的设置这些限制如下:

    //Look up the absolute minimum and absolute maximum values
    NSNumber * min = [allArraysDrawn valueForKeyPath:@"@min.intValue"];
    NSNumber * max = [allArraysDrawn valueForKeyPath:@"@max.intValue"];
    //Define the limits of the plot area with a cushion both above the max value and below the min value
    float yAxisMin = [min floatValue] - (([max floatValue] - [min floatValue]) * 0.05);
    float yAxisMax = [max floatValue] + (([max floatValue] - [min floatValue]) * 0.05);

有什么想法吗?谢谢!

【问题讨论】:

    标签: objective-c core-plot


    【解决方案1】:

    尝试CPTAxisLabelingPolicyAutomatic 轴标签策略。它将计算刻度线和网格线的“好”间隔。如果不满意,请使用默认的 CPTAxisLabelingPolicyFixedInterval 标记策略并选择所需的 10 次方 majorIntervalLength

    【讨论】:

    • 如果数字太大,是否有可以缩短数字的标签政策?例如:20k for 20,000,或3M for 3,000,000?
    • 您可以设置labelFormatter 来执行此操作。 NSNumberFormatter 有很多选择。
    • @EricSkroch 我没有使用 core-plot 但你能解释或展示它背后的逻辑吗?这真的很有帮助。
    • Core Plot 的“好”数字代码是here
    • @EricSkroch 是的,确实有效。该文件是否在两个最小值和最大值之间找到了合适的间隔数?
    猜你喜欢
    • 1970-01-01
    • 2015-11-12
    • 2021-03-23
    • 2013-09-18
    • 1970-01-01
    • 1970-01-01
    • 2011-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多