Skip to content
Advertisement

Create Altair chart with grouped dates by week in X axis

JavaScript

With a dataset like this, how can I create a bar chart grouped by week so the X axis shows only two bars, april 03 - april 09 and april 11 - april 17? (Taking into account that the week starts on sundays, even tho there is no data for dates like april 04)

Advertisement

Answer

You can use the time units in VegaLite to group observations. week() will return the week number, but I am not sure there is a way to format the label the way you want without doing it manually via labelExpr as I have done below.

JavaScript

enter image description here

You could also compute the labels via pandas first, which is more automatic than the above:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement