簡體   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