How to replace label values ​​in iOS diagrams?

I use IOS charts to draw download speeds. I give an array of chart functions double, which has byte values. He is building a chart. But I want to show the value of the chart labels in megabytes, kilobytes or bytes. I can convert bytes to this value using NSByteFormatter . But there is one problem: the function that builds the diagrams takes one array of values ​​(for example, an array of bytes) and displays the same values ​​in the labels on the diagram, I tried to find a solution for this, but I did not find any. How can i do this?

Function that draws a chart

  func setSendChart(description: [String], value: [Double]) { var chartDataEntryArray = [ChartDataEntry]() for item in 0..<description.count { let chartEntry = ChartDataEntry(value: value[item], xIndex: item) chartDataEntryArray.append(chartEntry) } let dataSet = LineChartDataSet(yVals: chartDataEntryArray, label: "") dataSet.drawCircleHoleEnabled = false dataSet.drawCirclesEnabled = false dataSet.drawCubicEnabled = true dataSet.drawFilledEnabled = true dataSet.drawValuesEnabled = false dataSet.fillColor = UIColor(red: 47/255, green: 206/255, blue: 255/255, alpha: 1.0) let chartData = LineChartData(xVals: description, dataSet: dataSet) sendChartView.data = chartData } 
0
source share
1 answer

You cannot change the value that the chart uses to draw; however, you can provide your own implementation of NSNumberFormatter to get the formatted value you need. yAxis matters yAxis , so dataSet

Another way is that you subclass the dataSet to pass your text array of values ​​and override renderAxisLabels or drawValues to draw the text you want.

I would prefer the first one, since it does not concern the library code

+3
source

Source: https://habr.com/ru/post/911523/


All Articles