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

Cannot add String labels to x axis. #2436

Open
danielvivek2006 opened this issue Nov 3, 2016 · 6 comments
Open

Cannot add String labels to x axis. #2436

danielvivek2006 opened this issue Nov 3, 2016 · 6 comments

Comments

@danielvivek2006
Copy link

Hey,
In ios we can add labels to x axis using
let data = LineChartData(xVals: ["1","2","3","4","5","6","7","8"], dataSets: [dataSet])

Why cant we add an Entry which takes String as argument instead of float.

Any other alternate except adding label outside view which is not a good practice ?

@vd92
Copy link

vd92 commented Nov 5, 2016

I have your problem too ,
in version 2 it could be done by using LineData but in version 3 i cant achieve this

@Lybron
Copy link

Lybron commented Nov 7, 2016

I just had to solve this issue migrating to version 3.0 as well.

Add this to your chart set up function:

self.chartView.xAxis.labelCount = self.chartXVals().count self.chartView.xAxis.valueFormatter = DefaultAxisValueFormatter { (value, axis) -> String in return self.chartXVals()[Int(value)] }

Where self.chartXVals() is a function returning an array of the desired x values; in my case date strings.

You can also refer to issue 1340 on the iOS repo here

@ghelfer
Copy link

ghelfer commented Dec 8, 2016

not works

@danielvivek2006
Copy link
Author

danielvivek2006 commented Dec 9, 2016 via email

@ghelfer
Copy link

ghelfer commented Dec 9, 2016

self.chartView.xAxis.labelCount shows me 6 items, but I have 8 bars...

@Lybron
Copy link

Lybron commented Dec 9, 2016

You may need to post a code sample for more insight. Especially where you're adding the x values.

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

4 participants