I am making some bar charts with vega-lite, using vega-lite-api; the raw data comes with a field called "month" with values like "2020/09" "2020/08" ... "2019/06" ...
the fieldT
recognized it nicely, and I can apply a brush to select narrower time ranges; but then the bar charts don't look good, it seems always a fixed value of width, too thin and the spacing between is too wide,
but in this visual, what makes more sense is to make the bar aligned to center of a month, because the data on y axis is aggregated for the whole month, not of a single date (first date of the month);
So how can make these bars to cover since beginning of each month till end of the month, and just leave a little gap (like 5px between? like in the fieldO
below)
if change x channel to use fieldO
of Ordinal values instead, then the width is better to wanted, and it adapts width well when brush select changes; but the month labels would be left as is, not so good;
It sounds like the feature you're looking for is the Time Unit. If you apply a timeUnit to a temporal encoding, it will cause the visual representation of the feature to fill the given timespan.
For example, here is some data similar to yours that uses a raw temporal encoding (view in editor):
You can apply a
yearmonth
timeUnit to the x encoding like this:If you do so, the result looks like this (view in editor):