Reputation: 2466
I am using the Charts framework. I was able to add the data to the chart but I am not able to change the X-axis labels on the chart.
Earlier, it could be done using:
Variables:
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
var sales = [230, 220, 240, 170, 90, 60, 150, 140, 160, 170, 140, 250]
ViewDidLoad:
let salesEntry1 = BarChartDataEntry(x: 0.0, y: 250)
let salesEntry2 = BarChartDataEntry(x: 1.0, y: 260)
salesEntries.append(salesEntry1)
salesEntries.append(salesEntry2)
let chartDataSet = BarChartDataSet(values: salesEntries, label: "Sales")
let chartData = BarChartData(dataSet: chartDataSet)
barChart.data = chartData
Upvotes: 1
Views: 179
Reputation: 2466
Currently as the old initializer is not available
Code:
let labels = ["Value 1", "Value 2"]
barChart.xAxis.valueFormatter = IndexAxisValueFormatter(values: labels)
Set the labels for each of the bars
Set granularity of X-Axis to 1
barChart.xAxis.granularity = 1
Note: This is a Swift 3 issue for Charts (v3.0.1)
Refer gitHub issues Charts/Issues/1800
Upvotes: 2