google / google-visualization-issues

288 stars 35 forks source link

Sort individual columns in stacked bar chart #2957

Open ksh-r opened 2 years ago

ksh-r commented 2 years ago

Hi everyone, I have a stacked bar chart where I want to sort each column based on the category sizes

Screenshot 2022-05-20 at 13 05 02

In the above image, each column has the category with max area on top. How do I implement this using google.visualization.arrayToDataTable? Here the order of categories is fixed for all columns but in the above image column 1 has blue category in the middle but column 3 has blue category on top.

dlaliberte commented 2 years ago

This is not possible currently, at least not directly. You can implement it yourself using current features plus doing your own sorting of the data. Here is an outline of what you will need to do:

You'll have to add style (for color) and tooltip (to display its original series) roles for each series, and also sort each row by the values, together with the style and tooltip for each value. The result will be new "series" that will be stacked as you want, but have colors and tooltips that correspond to the original data. You will want to hide the legend too, since it will be nonsensical.