I do not know the number of formatter that will scale the number (remove trailing zeros), with the exception of NSByteCountFormatter
. Therefore, you will need to scale each data point in a loop before adding it to your chart array. Maybe something like this.
Note: It seems very risky to outline something using only non-zero, significant numbers. Charts 12, 120, 1200, 12000 and 120000000000000 will show the same values.
func setReceivedChart(description: [String], value: [Double]) { let significantFigures = NSNumberFormatter() significantFigures.usesSignificantDigits = true significantFigures.maximumSignificantDigits = 2 var chartDataEntryArray = [ChartDataEntry]() for item in 0..<description.count { if let datum = significantFigures.stringFromNumber(value[item]) { datum.stringByReplacingOccurrencesOfString("0", withString: "", options: .LiteralSearch, range: nil) let chartEntry = ChartDataEntry(value: Double(datum), xIndex: item) chartDataEntryArray.append(chartEntry) } else { // handle error, keep charDataEntryArray in sync with description[] } } let dataSet = LineChartDataSet(yVals: chartDataEntryArray, label: "") dataSet.drawCircleHoleEnabled = false dataSet.drawCirclesEnabled = true // change dataSet.drawCubicEnabled = true dataSet.drawFilledEnabled = true dataSet.circleRadius = 3.0 // for iphone dataSet.drawValuesEnabled = true let numberFormatter = NSNumberFormatter() numberFormatter.numberStyle = .NoStyle dataSet.valueFormatter = numberFormatter // set color 47 206 255 dataSet.fillColor = UIColor(red: 47/255, green: 206/255, blue: 255/255, alpha: 1.0) let chartData = LineChartData(xVals: description, dataSet: dataSet) receivedChartView.data = chartData }
source share