contex
contex copied to clipboard
TimeSeries BarChart?
It looks like there is not a way to use the TimeSeries scale with a bar chart?
I like to use time series bar charts for things a lot. Would love to be able to do this Contex. I can try to implement if you're up for it?
Hi @chasers,
Yes - that's correct. Currently the bar chart is set up to use an "Ordinal Scale" only. This has a couple of special features to control plotting of bars - it has a get_band function that calculates the required width of a bar on the chart in plotting coordinates based on the required padding in plotting coordinates.
Ordinal Scale doesn't care about the data type, so you could easily create a dataset, sorted by date (and with pre-formatted date labels to make life easier) and feed that into the barchart. You would have to ensure regular time periods (e.g. daily) and create a row in the dataset for missing time periods with a zero value.
In terms of implementing a time series scale for a barchart, feel free. I'm happy to accept PRs. It may be worth getting your thoughts on use cases first and we could discuss possible approaches. There are a couple of potential approaches depending on what you are trying to achieve.
Thanks!
Yeah I've got it mostly there. This is now on our billing page:
I tried unsuccessfully to overwrite the x-axis with my own. It's just the labels get a little noisy with more than 30 days of data.
Can I simply customize the number of ticks in the x-axis? Like put a tick at every Nth column?
I'm evaluating this for more generalized simple dashboarding. So far I haven't run into any blockers really. LinePlot will be great!
Hi @chasers, looks good!
No - there isn't an option to label every Nth for the ordinal scale as yet. It wouldn't be hard to do at all. Or we could set a max_category_labels or similar on the BarChart and pass it through to the scale and have the scale calculate how many to skip. That would be pretty quick & simple to do.
It occurs to me that a simple (if sort of indirect) way to support this would be to add separate classes to the x and y-axis ticks and labels, and then let the user set the stroke/fill to none (or whatever) with :nth-of-type selectors. That would have no impact on the API (or existing style sheets) with the added benefit of allowing some more granular styling generally.