简体   繁体   English

Y轴正在重复值-iOS图表

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

In the iOS Chart Framework the y-values in the chart are repeating. iOS图表框架中,图表中的y值是重复的。 As shown in the picture below there are multiple 0's and 1's in the chart. 如下图所示,图表中有多个0和1。 在此处输入图片说明 Is there anyway I can customize this chart so there aren't any repeating y-values. 无论如何,我可以自定义此图表,因此没有重复的y值。 So in this scenario ideally the y-values should be 1,2,3,4,5. 因此,在这种情况下,理想情况下y值应为1,2,3,4,5。 I just don't want the y-values to repeat itself. 我只是不希望y值重复出现。

you could also try: 您也可以尝试:

/// 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

and set yAxis.granularity = some value 并设置yAxis.granularity =一些值

That's because the y-axis values currently have fractional values between 0 and 1. Those numbers are really 0, 0.2, 0.4, 0.6, 0.8, and 1. To format them properly try modifying the valueFormatter on the ChartYAxis : 这是因为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

The current range of the y-axis is 0 to 1 with 6 labels. y轴的当前范围是0到1,带有6个标签。 If you add values greater than 1 then the range will automatically adjust. 如果您添加的值大于1,则范围将自动调整。 You can also use customAxisMax to force the max value if the current range is not suitable. 如果当前范围customAxisMax ,也可以使用customAxisMax强制最大值。

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

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