Charts lineChartDataset rounded values

痴心易碎 提交于 2019-11-30 23:53:16

ios-charts have been upgraded to protocol base approach for rendering the various kind of labels like xAxis, yAxis etc. So you have to implement protocol IValueFormatter in order to achieve the required results. I have created the class for the same, so directly use this as below & you would be able to achieve desired results.

Create a class named as DigitValueFormatter & assign that to LineChartData object as lineChartData.setValueFormatter(DigitValueFormatter())

import Foundation
import Charts

class DigitValueFormatter : NSObject, IValueFormatter {

    func stringForValue(_ value: Double,
                        entry: ChartDataEntry,
                        dataSetIndex: Int,
                        viewPortHandler: ViewPortHandler?) -> String {
        let valueWithoutDecimalPart = String(format: "%.0f", value)
        return "\(valueWithoutDecimalPart)"
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!