Skip to content
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

custom xAxis for line chart I need an example #1905

Closed
Stay-in-Touch opened this issue Dec 1, 2016 · 3 comments
Closed

custom xAxis for line chart I need an example #1905

Stay-in-Touch opened this issue Dec 1, 2016 · 3 comments

Comments

@Stay-in-Touch
Copy link

I have 4800 y values at 80 values/s. I want teh xAxis Lables to read 0s,15s,30s,45s at the 0,1200,2400 and 3600 positions. It is not at all clear to me how to approach this issue. I would like vertical grid lines from each label!

Living in a time of transition is uncomfortable, and many of the old examples and even running code no longer work. Is there an example of Swift 3 line charts that I could look at.
Thank you

@r-dent
Copy link

r-dent commented Dec 2, 2016

I would love to see such, too. I created an issue (#1909) with my concrete example. Maybe it helps.

@Stay-in-Touch
Copy link
Author

Making some progress....
// xAxis let xAxis = lineChartView.xAxis xAxis.labelPosition = .bottom xAxis.drawLabelsEnabled = true xAxis.labelTextColor = UIColor.red xAxis.labelFont = NSUIFont.systemFont(ofSize: 11.0) let labels = ["0s","15s","30s","45s",""] xAxis.valueFormatter = IndexAxisValueFormatter(values: labels) xAxis.setLabelCount(labels.count, force: true) lineChartView.scaleXEnabled = true

This produces...
image

Note the 0s in red at the beginning of the x Scale. Problem now is to show the others.
The trick to getting the right number of grid lines is to add the "" for the last position of the scale.

@liuxuan30
Copy link
Member

liuxuan30 commented Dec 6, 2016

you can take a look at computeAxisValues(), where it generate the x axis value labels.
I don't quite understand what you want, but looks like overriding the func and set the interval to be 15sec seems doable to me.
setting label count would just take interval = (max -min) / labelCount, so the value labels may not see nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants