altair icon indicating copy to clipboard operation
altair copied to clipboard

[Question] Optional Sorting of Bar Chart X-axis

Open bminie opened this issue 4 years ago • 2 comments

I was wondering if it's possible to add a drop down menu and link it to a bar chart so that when the button is selected the bar chart will sort the X-axis by the Y-axis values smallest to largest and when it isn't selected if should use the standard X-axis sorting (my values are years). I'm able to create the chart and drop down menu but I'm not sure how to link the two together so when the user selects an option in the dropdown the chart will respond accordingly. Any help is appreciated!

bminie avatar Apr 08 '21 19:04 bminie

I believe that this will not be possible until Altair supports parameters, which were recently added to Vega-Lite. You can see the example in the most recent Vega-Lite docs for something similar to what you are asking.

joelostblom avatar Apr 08 '21 21:04 joelostblom

@joelostblom thanks for the info. I was able to use a dropdown menu to change what is plotted/displayed on a line graph and was hoping I'd be able to do the sorting with a similar mechanism. I'll definitely keep an eye out for when this is possible. In case you are curious, here is the functionality I was describing.

https://user-images.githubusercontent.com/38255038/114104218-74629200-9898-11eb-8b36-659aa3bf90cf.mp4

bminie avatar Apr 08 '21 22:04 bminie

I tested this a bit in the development version of altair and I don't think it will be possible until Vega-Lite adds support for using parameters everywhere so that you can set the sort param as an expression. Another way would be if Vega-Lite had support for using condition for positional channels in addition to mark property channels which are the only ones supported now. So for now I will close this since there is nothing that can be done on the altair side of things, but feel free to request these feature on the Vega Lite issue tracker.

joelostblom avatar Feb 06 '23 01:02 joelostblom