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

[FEATURE] add option to order axes #4092

Closed
cizmiak opened this issue Mar 30, 2017 · 3 comments
Closed

[FEATURE] add option to order axes #4092

cizmiak opened this issue Mar 30, 2017 · 3 comments

Comments

@cizmiak
Copy link
Contributor

cizmiak commented Mar 30, 2017

Expected Behavior

If i set order number property in scale options for some axes, these axes should by ordered by this number.

Current Behavior

There is no such option. Now, axes have same order as results from Object.keys(chart.scales) which is arbitrary and could be unexpected.

Context

Enable to user to set axis ordering.

Environment

  • Chart.js version: 2.5
@etimberg
Copy link
Member

@cizmiak you're in luck! We recently added some code to allow arbitrary position of other items on the canvas (legend, title, etc) to ensure they can be sorted by a weight field. We made the underlying code generic enough so it should be easily adapted to axes too!!

When items are added to the layout system via addBox we check to see if layoutItem.weight is defined and default it to 0. https://github.com/chartjs/Chart.js/blob/master/src/core/core.layoutService.js#L65-L67

The axes get added to the layout system here: https://github.com/chartjs/Chart.js/blob/master/src/core/core.scaleService.js#L39

When the axis is constructed here you could set some weight if it's set in the options. In the legend the value of the weight parameter is hard coded.

I'm happy to look at a PR for this :)

@cizmiak
Copy link
Contributor Author

cizmiak commented Mar 31, 2017

@etimberg , thanks for giving me direction.

@etimberg
Copy link
Member

etimberg commented Apr 4, 2017

Done in #4094

@etimberg etimberg closed this as completed Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants