[英]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.