Bar charts sort labels alphabetically instead of respecting their order
simonw opened this issue · 7 comments
Pointed out here: https://twitter.com/zellyn/status/1391786830333464579
Here's why:
It's because of type: "nominal"
.
I am finding it remarkably difficult to figure out how to get Vega-Lite bar charts to respect the initial order (I remember having this same problem with datasette-vega
): https://vega.github.io/vega-lite/docs/bar.html
@simonw I do not know if it's ok for you. have you tried with "sort": {"field": "fieldname"}
?
That's not quite what I'm after here - I want to sort in the order originally provided by the results of the query.
So if the data looked like this:
{
"values": [
{"a": "Dog", "b": 28},
{"a": "Cat", "b": 55},
{"a": "Chicken", "b": 43},
{"a": "Dragon", "b": 91}
]
}
I want the bars on the bar chart to be in Dog
, Cat
, Chicken
, Dragon
order.
Aha! It looks like "sort": null
does the trick. https://vega.github.io/vega-lite/docs/sort.html#no-sorting
I can fix simonw/datasette-vega#19 with this too.