0
아주 간단한 값으로 그룹화 된 막 대형 차트를 만들었습니다. 나는 각 xaxis 레이블과 일치하도록 xaxis 및 3 bar 그룹을 따라 펼쳐지는 5 개의 레이블을 가지고 있습니다.ios-charts xaxis 레이블에 줄이 없음
그래프에 이제 1 개의 xaxis 레이블과 1 개의 막대가 표시됩니다. (프레임이 틀릴 수도 있습니다.) 정확한 msArrayAxis 레이블로 동기화하려면 각 사례가 필요합니다.
var msArrayXAxis = ["0-20", "20-50", "50-100", "100-200", "<200"]
barchartView.isUserInteractionEnabled = false
barchartView.noDataText = "You need to provide data for the chart."
barchartView.legend.enabled = false
barchartView.chartDescription?.text = ""
barchartView.xAxis.labelPosition = XAxis.LabelPosition.bottom
barchartView.xAxis.valueFormatter = IndexAxisValueFormatter(values: msArrayXAxis)
barchartView.xAxis.axisMinimum = 0
barchartView.xAxis.granularity = 2
barchartView.xAxis.setLabelCount(5, force: true)
barchartView.xAxis.spaceMin = 0.3
// barchartView.extraBottomOffset = 1
barchartView.xAxis.labelWidth = 1
barchartView.xAxis.avoidFirstLastClippingEnabled = true
barchartView.rightAxis.drawGridLinesEnabled = false
barchartView.rightAxis.drawAxisLineEnabled = false
barchartView.rightAxis.drawLabelsEnabled = false
func parsedArrayCount(case1: Array<Double>,case2: Array<Double>,case3: Array<Double>,case4: Array<Double>, case5: Array<Double>) -> [BarChartDataEntry] {
var dataEntries1: [BarChartDataEntry] = []
NSLog("Parsing array count")
let dataEntry = BarChartDataEntry(x: Double(0), y:Double(case1.count))
dataEntries1.append(dataEntry)
let dataEntry2 = BarChartDataEntry(x: Double(1), y:Double(case2.count))
dataEntries1.append(dataEntry2)
let dataEntry3 = BarChartDataEntry(x: Double(2), y:Double(case3.count))
dataEntries1.append(dataEntry3)
let dataEntry4 = BarChartDataEntry(x: Double(3), y:Double(case4.count))
dataEntries1.append(dataEntry4)
let dataEntry5 = BarChartDataEntry(x: Double(1), y:Double(case5.count))
dataEntries1.append(dataEntry5)
return dataEntries1
}
func updateGraph(array: Array<name>?) {
var dataEntries1: [BarChartDataEntry] = []
var dataEntries2: [BarChartDataEntry] = []
var dataEntries3: [BarChartDataEntry] = []
barchartView.clear()
rArray.removeAll()
nameArray.removeAll()
if array != nil && array!.count > 0 {
for i in 0..<array!.count {
rArray.append(array![i].r)
nameArray.append(array![i].name)
}
NSLog("updating graph..")
let name = Analyzer.sharedInstance.nameArray(names: rArray.map{String($0)}, Name: nameArray)
let cData = parserArrays(rArray: name.first.map {Double($0)!})
let wData = parserArrays(rArray: name.last.map {Double($0)!})
let vData = parserArrays(rArray: name.middle.map {Double($0)!})
dataEntries1 = parsedArrayCount(case1: cData.case1, case2: cData.case2, case3: cData.case3, case4: cData.case4, case5: cData.case5)
dataEntries2 = parsedArrayCount(case1: wData.case1, case2: wData.case2, case3: wData.case3, case4: wData.case4, case5: wData.case5)
dataEntries3 = parsedArrayCount(case1: vData.case1, case2: vData.case2, case3: vData.case3, case4: vData.case4, case5: vData.case5)
let chartDataSet = BarChartDataSet(values: dataEntries1, label: "")
chartDataSet.colors = [UIColor.Blue()]
let chartDataSet1 = BarChartDataSet(values: dataEntries2, label: "")
chartDataSet1.colors = [UIColor.Green()]
let chartDataSet2 = BarChartDataSet(values: dataEntries3, label: "")
chartDataSet2.colors = [UIColor.Orange()]
NSLog("Data set1 \(dataEntries1)")
let groupSpace = 1.0
let barSpace = 0.05
let barWidth = 0.1
/* let xAxis = XAxis()
xAxis.valueFormatter = self
xAxis.drawGridLinesEnabled = true
xAxis.labelPosition = .bottom
xAxis.centerAxisLabelsEnabled = true
barchartView.xAxis.valueFormatter = xAxis.valueFormatter*/
let dataSets: [BarChartDataSet] = [chartDataSet,chartDataSet1]
let chartData = BarChartData(dataSets: dataSets)
chartData.setDrawValues(false)
chartData.barWidth = barWidth
chartData.groupBars(fromX:0.3, groupSpace: groupSpace, barSpace: barSpace)
// let gg = chartData.groupWidth(groupSpace: groupSpace, barSpace: barSpace)
// barchartView.xAxis.axisMaximum = Double(0) + gg * Double(msArrayXAxis.count)
barchartView.data = chartData
barchartView.animate(yAxisDuration: 0.5)
}
}