2016-11-18 48 views
1

我已將我的值存儲在覈心數據中並在BarChart中顯示。 我的類別金額在8.5和420.10。圖表3.0 - 無法在BarChart中顯示小數 - iOS Swift

但條形圖中的顯示爲8和420. 應該如何設置十進制值?

enter image description here

var dataEntries: [BarChartDataEntry] = [] 

    for i in 0..<dataPoints.count { 
    let value = values[i] as Double 
    print("value=\(value)") 
    let dataEntry = BarChartDataEntry(x: Double(i), y:value) 
    dataEntries.append(dataEntry) 
} 

let chartDataSet = BarChartDataSet(values: dataEntries, label: "Total Amount") 
chartDataSet.colors = [.red, .yellow, .green, .blue, .brown] 
chartDataSet.colors = ChartColorTemplates.joyful() 
barChartView.xAxis.labelPosition = .bottom 
barChartView.chartDescription?.text = "" 
barChartView.xAxis.drawGridLinesEnabled = false 
barChartView.leftAxis.drawLabelsEnabled = false 
barChartView.leftAxis.granularityEnabled = true 

let chartData = BarChartData() 
chartData.addDataSet(chartDataSet) 
barChartView.data = chartData 

回答

2

我得到了答案:

let format = NumberFormatter() 
format.numberStyle = .decimal 
let formatter = DefaultValueFormatter(formatter: format) 
chartData.setValueFormatter(formatter) 
0

嘗試使用NSNumberFormatter:

let numberFormatter = NumberFormatter() 
numberFormatter.numberStyle = .decimal 
barChartView.leftAxis.valueFormatter = numberFormatter 

嘗試看看這是條價值類,並應用它在那裏,可能會有

+0

錯誤:不能指定'NumberFormatter'類型的值來鍵入'IAxisValueFormatter' – user831098

+0

你使用Swift 3嗎? – Tj3n

+0

是的,我正在使用Swift3 – user831098

相關問題