I am working on ios-charts by Daniel Gindi on swift 3.0. I have written following code for bar charts
var dataEntries: [BarChartDataEntry] = []
for i in 0..<dateTime.count {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM/dd/yyyy hh:mm:ss aa"
let dateObj = dateFormatter.date(from: dateTime[i])
let timeIntervalForDate = dateObj!.timeIntervalSince1970
let dataEntry = BarChartDataEntry(x: Double(timeIntervalForDate), y: Double(readings[i]))
dataEntries.append(dataEntry)
}
let chartDataSet = BarChartDataSet(values: dataEntries, label: "Units")
let chartData = BarChartData(dataSet: chartDataSet)
self.ChartsView.data = chartData
i get following result in emulator:
you can see no red line reflecing my values. I even zoomed to charts but nothing was shown.
I also tried line chart with sample values. Here is the code:
let dollars1 = [20.0, 4.0, 6.0, 3.0, 12.0, 16.0, 4.0, 18.0, 2.0, 4.0, 5.0, 4.0]
let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
var yValues : [ChartDataEntry] = [ChartDataEntry]()
for i in 0 ..< months.count {
yValues.append(ChartDataEntry(x: Double(i + 1), y: dollars1[i]))
}
let LineData = LineChartData()
let ds = LineChartDataSet(values: yValues, label: "Months")
LineData.addDataSet(ds)
self.ChartsView.data = LineData
Its result is even more weird. No grid lines are shown either in this chart. Here is the image.
I am not sure what is wrong with these graphs. Am I missing something. So far i am unable to look any furthur as most solutions are using old version of charts(or may be it is something else i am not aware). Please guide me to proper direction. Thanks
I am struggling with Version 3.0 and Swift 3 and the lack of documentation... May I point you to the best text on the subject which can be found here
Xvals as Parameters are gone, instead you use two-dimensional data on axis
Regarding your problem with timevalues.. you could use the "timeIntervalSince1970" of the date-object and format things with an extension
all of which is to be found at the link mentioned above