contex icon indicating copy to clipboard operation
contex copied to clipboard

TimeSeries BarChart?

Open chasers opened this issue 4 years ago • 4 comments
trafficstars

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?

chasers avatar Jan 12 '21 12:01 chasers

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.

mindok avatar Jan 12 '21 22:01 mindok

Thanks!

Yeah I've got it mostly there. This is now on our billing page:

Screen Shot 2021-01-12 at 3 44 18 PM

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!

chasers avatar Jan 12 '21 22:01 chasers

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.

mindok avatar Jan 13 '21 00:01 mindok

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.

srowley avatar Feb 14 '21 02:02 srowley