Я использую библиотеку диаграмм (https://github.com/danielgindi/Charts, Спасибо Даниэлю) для рисования различных диаграмм в приложениях Android и IOS.Мне нужны сгруппированные гистограммы и значения баров высоки.Поэтому, когда я отображаю, значения перекрываются.Я использовал пользовательский рендерер для своего приложения Android, и он будет показывать значения по вертикали, как на скриншоте.Теперь мне нужно то же самое для приложения IOS.
Вот мой быстрый код для ios:
func setBarChart(barchart: BarChartView, chartData: BarData){
let groupSpace = 0.16
let barSpace = 0.03
let barWidth = 0.25
let yearlyData = [YearlyData] (chartData.data!)
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
let tempData1 = [ReportData] (yearlyData[0].data!)
let tempData2 = [ReportData] (yearlyData[1].data!)
let tempData3 = [ReportData] (yearlyData[2].data!)
var yearlyData1 = [Double]()
var yearlyData2 = [Double]()
var yearlyData3 = [Double]()
for i in 0..<12 {
yearlyData1.append(Double(tempData1[i].value!)!)
yearlyData2.append(Double(tempData2[i].value!)!)
yearlyData3.append(Double(tempData3[i].value!)!)
}
barchart.noDataText = "no_data_found".localized
barchart.noDataTextColor = textColour
barchart.chartDescription?.text = ""
barchart.drawValueAboveBarEnabled = true
barchart.legend.enabled = true
barchart.xAxis.drawGridLinesEnabled = false
barchart.xAxis.labelTextColor = textColour
barchart.xAxis.labelPosition = .bottom
barchart.xAxis.labelCount = months.count
barchart.xAxis.labelRotationAngle = 0.0
barchart.xAxis.valueFormatter = IndexAxisValueFormatter(values:months)
barchart.xAxis.granularityEnabled = true
barchart.xAxis.granularity = 1
barchart.xAxis.axisMinimum = 0
barchart.xAxis.centerAxisLabelsEnabled = true
barchart.xAxis.axisMaximum = 12
barchart.xAxis.labelPosition = .top
barchart.rightAxis.enabled = false
barchart.leftAxis.labelTextColor = textColour
barchart.leftAxis.drawGridLinesEnabled = false
barchart.leftAxis.axisMinimum = 0
barchart.fitBars = true
var dataEntries1: [BarChartDataEntry] = []
var dataEntries2: [BarChartDataEntry] = []
var dataEntries3: [BarChartDataEntry] = []
var counter = 0.0
for i in 0..<months.count {
let dataEntry1 = BarChartDataEntry(x: counter, y: yearlyData1[i])
dataEntries1.append(dataEntry1)
let dataEntry2 = BarChartDataEntry(x: counter, y: yearlyData2[i])
dataEntries2.append(dataEntry2)
let dataEntry3 = BarChartDataEntry(x: counter, y: yearlyData3[i])
dataEntries3.append(dataEntry3)
counter += 1.0
}
let chartDataSet1 = BarChartDataSet(values: dataEntries1, label: "2017")
chartDataSet1.colors = [UIColor.red]
chartDataSet1.valueColors = [textColour]
let chartDataSet2 = BarChartDataSet(values: dataEntries2, label: "2018")
chartDataSet2.colors = [UIColor.orange]
chartDataSet2.valueColors = [textColour]
let chartDataSet3 = BarChartDataSet(values: dataEntries3, label: "2019")
chartDataSet3.colors = [UIColor.green]
chartDataSet3.valueColors = [textColour]
let chartData = BarChartData()
chartData.addDataSet(chartDataSet1)
chartData.addDataSet(chartDataSet2)
chartData.addDataSet(chartDataSet3)
chartData.barWidth = barWidth
barchart.data = chartData
barchart.setVisibleXRangeMaximum(4.0)
barchart.groupBars(fromX: 0, groupSpace: groupSpace, barSpace: barSpace)
barchart.animate(yAxisDuration: 0.5, easingOption: .easeInExpo)
}