Forum Discussion
mojganmeibodi19
2 years agoRegular Visitor
sorting legend based on two criteria
I have a simple dataset that contains each supplier's sale in each year. I made a bar chart with years in the x axis and suppliers' sale on the y axis and used supplier company as legend. I wa...
dm-p
2 years agoSuper User
Vega and Vega-Lite don't have sorting capabilities for more than one field using standard language constructs, but you can use transforms and window functions to create fields that dictate a sort order that you can then sort by.
lbendlin
2 years agoSuper User
Could you layer the individual columns as separate marks with their own sort order? Or would you have to know the number of columns/marks beforehand?
- dm-p2 years agoSuper User
Whatever the layer, if they share the same encoding channel, Vega will likely resolve them to the same scale (and sort). Your best bet would be to use a window transform to generate a numeric order based on grouping and sorting of multiple fields in the dataset and then sort on that.