Y轴是重复值 - iOS图表

时间:2016-05-06 01:57:33

标签: ios swift ios-charts

iOS Chart Framework中,图表中的y值重复出现。如下图所示,图表中有多个0和1。enter image description here无论如何,我可以自定义此图表,因此没有任何重复的y值。因此,在这种情况下,理想情况下,y值应为1,2,3,4,5。我只是不希望y值重复出现。

2 个答案:

答案 0 :(得分:5)

您也可以尝试:

/// When true, axis labels are controlled by the `granularity` property.
/// When false, axis values could possibly be repeated.
/// This could happen if two adjacent axis values are rounded to same value.
/// If using granularity this could be avoided by having fewer axis values visible.
public var granularityEnabled = false

并设置yAxis.granularity =某个值

答案 1 :(得分:1)

那是因为y轴值目前的小数值介于0和1之间。这些数字实际上是0,0.2,0.4,0.6,0.8和1.要正确格式化它们,请尝试修改{{1在valueFormatter

ChartYAxis

y轴的当前范围是0到1,带有6个标签。如果添加大于1的值,则范围将自动调整。如果当前范围不合适,您还可以使用let yAxis = chart.leftAxis let yAxisValueFormatter = NSNumberFormatter() yAxisValueFormatter.usesSignificantDigits = true // This will tell the formatter to display the decimal places yAxis.valueFormatter = yAxisValueFormatter 强制最大值。