I have a chart that takes time series data. The time series data is recorded at most once per day, but on an irregular schedule. I.e., the data could look like this:
1/1, 1500
1/13, 1600
1/14, 1700
2/22, 1800
5/1, 1400
Using Charts, my line graph populates the x-axis with one unit per data point (i.e., in the example above, there would be 5 units on the xaxis, instead of ~120 days)
How do I create the x-axis with units for all dates in range?
The code for my chart:
func setChartData(data: ([String], [Double])) {
var yVals1 = [ChartDataEntry]()
for i in 0 ..< data.0.count {
yVals1.append(ChartDataEntry(value: data.1[i], xIndex: i))
}
let set1: LineChartDataSet = LineChartDataSet(yVals: yVals1, label: nil)
set1.axisDependency = .Left
set1.setColor(UIColor(red:0.502, green:0.580, blue:0.784, alpha:1.000))
set1.lineWidth = 2.0
set1.fillAlpha = 1
set1.fillColor = UIColor(red:0.502, green:0.580, blue:0.784, alpha:1.000)
set1.highlightColor = UIColor.whiteColor()
set1.drawValuesEnabled = false
set1.drawCirclesEnabled = false
set1.drawFilledEnabled = true
var dataSets : [LineChartDataSet] = [LineChartDataSet]()
dataSets.append(set1)
let data: LineChartData = LineChartData(xVals: data.0, dataSets: dataSets)
data.setValueTextColor(UIColor.whiteColor())
let legend = lineChartView.legend
legend.enabled = false
let xAxis = lineChartView.xAxis
xAxis.drawGridLinesEnabled = false
xAxis.drawAxisLineEnabled = false
xAxis.labelPosition = .Bottom
let rightAxis = lineChartView.rightAxis
rightAxis.drawAxisLineEnabled = false
rightAxis.drawLabelsEnabled = false
rightAxis.drawGridLinesEnabled = false
let leftAxis = lineChartView.leftAxis
leftAxis.drawAxisLineEnabled = false
leftAxis.gridColor = UIColor.blackColor().colorWithAlphaComponent(0.1)
leftAxis.gridLineWidth = 2
self.lineChartView.data = data
}