我已经将我的价值存储在核心数据中并在BarChart上显示了。
我的类别数量是8.5和420.10。

但是条形图上的显示是8和420。
我应该如何设置十进制值?

ios - Charts 3.0-无法在BarChart中显示小数-iOS Swift-LMLPHP

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

最佳答案

我得到答案:

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

09-16 21:39