繁体   English   中英

Y轴正在重复值-iOS图表

[英]Y-axis is repeating values - iOS Charts

iOS图表框架中,图表中的y值是重复的。 如下图所示,图表中有多个0和1。 在此处输入图片说明 无论如何,我可以自定义此图表,因此没有重复的y值。 因此,在这种情况下,理想情况下y值应为1,2,3,4,5。 我只是不希望y值重复出现。

您也可以尝试:

/// 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 =一些值

这是因为y轴值当前具有介于0和1之间的小数值。这些数字实际上是ChartYAxis和1。要正确格式化它们,请尝试在ChartYAxis上修改valueFormatter

let yAxis = chart.leftAxis

let yAxisValueFormatter = NSNumberFormatter()
yAxisValueFormatter.usesSignificantDigits = true  // This will tell the formatter to display the decimal places
yAxis.valueFormatter = yAxisValueFormatter

y轴的当前范围是0到1,带有6个标签。 如果您添加的值大于1,则范围将自动调整。 如果当前范围customAxisMax ,也可以使用customAxisMax强制最大值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM