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

Rounding yLabels #151

Closed
ghost opened this issue Jan 2, 2013 · 3 comments
Closed

Rounding yLabels #151

ghost opened this issue Jan 2, 2013 · 3 comments

Comments

@ghost
Copy link

ghost commented Jan 2, 2013

I have plotted some JSON data using Morris.js. The graph works great (and thanks for such an awesome charting tool), however I'm trying to tweak the labels along the y-axis in a line chart.

Currently, the yLabels are being automatically generated by morris.js using the JSON data's range of values (where x-axis is time). In my example JSON, values range from 54 to -47, so the yLabels being generated are 54, 29, 4, -22, -47. Instead, however, I'd like to round these values to -50, -25, 0, 25, and 50. I would also like the "0" line to stand out, hopefully with a different colour.

As I'm dynamically creating the data, these won't be fixed, in another chart the values may range between -2.5 and +2.5 (in which case I'd want the labels along the y axis to be -2.5, -1.25, 0, 1.25, 2.5).

How would I round the labels morris.js is creating and make the "0" line red?

I have tried creating an array of yLabels (yLabels: ['-50','-25','0','25','50'],), but it didn't work, and even if it had I don't want to "hard-code" values because as I said, each chart will be different and dynamically generated.

Any help is greatly appreciated.

@ghost
Copy link
Author

ghost commented Jan 2, 2013

In the first example, I have been able to get what I want putting ymin and ymax of -50 and 50 respectively, but like I mentioned, I don't want to hard-code these values as the ymin/max will vary depending on the JSON being parsed. Is there a way I can always ensure the middle line is always 0, and morris determines the two y values above and below it?

@tiraeth
Copy link
Contributor

tiraeth commented Jan 2, 2013

This is also something I need. E.g. I am displaying number of people doing something and get yLabels with values like 5.25 people. Awkward, isn't it ;) ?

Probably I will post a PR in a couple of days. This will also include rounding to nearest 10-th, 100-th and so on.

@oesmith
Copy link
Contributor

oesmith commented Jan 25, 2013

Closing this as a dupe of #162.

@oesmith oesmith closed this as completed Jan 25, 2013
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

2 participants