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

Option to reverse render order of datasets #6050

Closed
mkstix6 opened this issue Feb 7, 2019 · 8 comments · Fixed by #6268
Closed

Option to reverse render order of datasets #6050

mkstix6 opened this issue Feb 7, 2019 · 8 comments · Fixed by #6268

Comments

@mkstix6
Copy link

mkstix6 commented Feb 7, 2019

[edited]
Feature request: option to choose the order stacked areas are drawn.

image

I have a stacked-filled-line-chart made with Chart.js

✅ The Input Data is alphabetically sorted.
✅ The Legend is alphabetically sorted.
☹️ But the chart itself is sorted top-to-bottom-reverse-alphabetical.
…visually this makes the chart and the legend sorted the opposite way to each other.

I would like to reverse the order of the chart's stacked areas without reversing both the data and the legend. I know I can do both these things individually but it just seems silly to have to achieve the result I'm looking for this way.

Thank you for a wonderful charting library.

@benmccann
Copy link
Contributor

The answer you got on StackOverflow is correct. Passing the data in the order you want it to be rendered is the only way to handle this for now

@mkstix6
Copy link
Author

mkstix6 commented Feb 7, 2019

Hi @benmccann. Would it be appropriate for me to write up a feature-request or is this a complete no-go.
Perhaps an option for sorting the order the areas are stacked in.
Default stays like it is now.
I don't know how the internal rendering works though 🤷‍♂️.

@mkstix6
Copy link
Author

mkstix6 commented Feb 7, 2019

…trying to think of a concrete reason why it renders this way round actually.
Do you think it was a choice or perhaps this bottom-to-top rendering is just easier for calculating the cumulative totals.
Perhaps a request to reverse the order by default is appropriate?

@simonbrunel simonbrunel reopened this Feb 7, 2019
@benmccann benmccann changed the title Chart.js reverse render order of stacked areas (perhaps a mini-feature option request) Option to reverse render order of datasets Feb 7, 2019
@simonbrunel
Copy link
Member

simonbrunel commented Feb 7, 2019

It's kind of a duplicate of #2399, right? Since this one has been closed long time ago, I'm reopening this one to keep track of that feature. IMO, we should add support for dataset sorting, maybe via a new order option. That's something I referred to in this comment, initially via the weight option.

Actually, the dataset order would allow to easily change the drawing/stacking order but would also impact the order in the legend, so I'm not sure it would solve your issue.

@mkstix6 no need to create a new ticket but instead can you please edit the description of this one as a feature request?

@mkstix6
Copy link
Author

mkstix6 commented Feb 11, 2019

@simonbrunel Thanks. I've made an edit. How's that looking?

@jan-tosovsky-cz
Copy link

It sounds like duplicate of #4161

@mkstix6
Copy link
Author

mkstix6 commented Jun 28, 2019

It sounds like duplicate of #4161

Yes it sounds like the same issue for different chart types. I don't know enough about the under-the-hood parts myself but if this can be solved for both chart types in one go that would be super.

@pierreben
Copy link

As  dataset.order also has an impact on the legends ordering the solution for the original need would be to use the order attribute on the dataset, combined with a specific sort on the legend plugin option in the generateLabels function :

Something like :

    options: {
      plugins: {
        legend: {
          labels: {
            generateLabels: function(chart) {
              const legendItems = Chart.defaults.plugins.legend.labels.generateLabels(chart);
              legendItems.sort((a, b) => a.text.localeCompare(b.text));
              return legendItems;
            }
          }
        }
      }
    }

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

Successfully merging a pull request may close this issue.

5 participants