[BUG] bar charts scales are inconsistent when type: ‘time’ and unit: ‘week’ OR ‘month’

Expected Behavior

I expected the graph chart to remain consistent, and for only the xAxis time format to change.

Current Behavior

The xAxis scale seems to increase too much, and data is lost in both the week and month (more than week) charts.
Clumping the bars together as a week or month metric seems to be the root of the problem.

Possible Solution

I suggest that when bar charts (stacked, or not) have type: 'time' configured, display the bars as days, keeping the chart graph itself consistent, and only change the axis labeling (days, weeks, months).

We need to ask ourselves if we think this is working as intended or not. Here are my opinions

Leaving it the way it is (clumping up data by week/month)

Pros: ??

Cons

  1. truth of the original data is altered
  2. some data will be hidden/truncated (bad!)
  3. stacking bar charts seems to exacerbate the previous 2 problems
Making a special case for bar charts with the ‘time’ configuration always display the chart in day bars

Pros:

  1. we avoid all the Cons of leaving it the way it is

Cons:

  1. We break convention, adding a special case to one of the chart types, possibly breaking backwards compatibility

Maybe we can avoid the last con by adding another configuration option that gives us the ability to be flexible with how we want the chart to render.

Steps to Reproduce (for bugs)

  1. Look at my demos
  2. Compare the data in the graph vs all 3 types of time units (day, week, month)
  3. Assert the data does not stay consistent, is often truncated on the right-hand-side, and could be avoided if bar charts only used days for bars rather than attempting to clump weeks and months together somehow.

Context

I’m trying to represent data with a clear bar chart, provide 3 options for the xAxis scale labels (days, weeks, months).

Environment

  • Chart.js version: 2.4.0
  • Browser name and version: Any
  • Link to your projects:

Bar Chart (stacked)

https://jsfiddle.net/5y0rk63a/

This demo shows a big difference in the way the chart is rendered when the scale unit differs.

Bar Chart

https://jsfiddle.net/5y0rk63a/1/

This demo is fork of the stacked bar chart, with hopes to further isolate the root cause. It contains a single dataset, and does not stack any bar data.

Author: Fantashit

1 thought on “[BUG] bar charts scales are inconsistent when type: ‘time’ and unit: ‘week’ OR ‘month’

Comments are closed.