Reputation: 981
I am using the Charts framework found here.
My graphs look like this:
My left graph has a bunch of values under my first bar and my second graph is missing a value under my second bar. My function to set up the graph is as follows:
func setChart(chartview: BarChartView, xarray: [String], yarray: [Double]){
var dataEntries: [BarChartDataEntry] = []
for i in 0..<xarray.count {
let dataEntry = BarChartDataEntry(x: Double(i), y: Double(yarray[i]))
dataEntries.append(dataEntry)
}
let chartDataSet = BarChartDataSet(values: dataEntries, label: "")
let chartData = BarChartData(dataSet: chartDataSet)
chartview.xAxis.valueFormatter = IndexAxisValueFormatter(values:xarray)
chartview.xAxis.labelPosition = .bottom
chartview.chartDescription?.enabled = false
chartview.rightAxis.enabled = false
chartview.legend.enabled = false
chartview.data = chartData
}
I use the same functions to create other graphs and they show up fine but for some reason sometimes they show like this.
Update:
Below are both arrays during runtime for each graph:
Graph 1:
["iOS 10", "iOS 9"]
[67.0, 19.0]
Graph 2:
["2.1.0.6", "2.1.0.5", "2.0.32", "2.0.30", "2.0.23", "1.3.2.8"]
[67.0, 7.0, 4.0, 5.0, 2.0, 1.0]
Upvotes: 2
Views: 731