-
-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Charts 3.0: How to set x-values for a line chart? #1627
Comments
You haven't searched enough... You can see the demos, or this: |
This is not terribly responsive. By "searching around" I did intend to mean that I had read the migration note, and looking at the demos. Despite this, the answer to my question is not apparent. All of the demos have one y value per x value. The I want a graph that has more x value than y values. This is similar to #1584 although I'm not sure I understand the workaround described (setting min/max x axis values). |
@arienmalec not very clear what's your issue. If you want to set x values, just follow line chart or Time Line Chart in ChartsDemo. I'ts enough info |
Here's the solution for posterity: Where the code was previously: let d = LineChartData(xVals: xLabels, dataSet: dataSet)
//...
self.data = d The Charts 3.0 version is: let d = LineChartData(dataSet: dataSet)
self.data = d
self.xAxis.valueFormatter = XValsFormatter(xVals: xLabels)
xAxis.axisMinimum = Double(0)
xAxis.axisMaximum = Double(presenter.xLabels.count - 1) class XValsFormatter: NSObject, IAxisValueFormatter {
let xVals: [String]
init(xVals: [String]) {
self.xVals = xVals
}
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
return xVals[Int(value)]
}
} |
I want a line chart that represents temporal data with x labels for each timeperiod (e.g., each day), and x-y values only for collected data.
In the previous version, I did this like so:
This constructor no longer exists, and despite searching around, I haven't seen a clear substitute.
What's the Charts 3.0 equivalent?
The text was updated successfully, but these errors were encountered: