chartjs / chartjs/Chart.js

Time Cartesian Axis does not accumulate data points on unit change

Open
#11,625 0 comments 1 reaction 0 assignees View on GitHub
type: enhancement
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### Feature Proposal

Time Axis claims to support different resolutions like days, weeks, etc.
However, the collisions of data points is completely ignored by it.

For example,
GIVEN two transactions have arrived on the same day. 100 USD received at 3pm, another one - 200 USD at 4pm .
AND `hour` unit is selected - it's ok to render them as two data points
WHEN unit is changed to `days`(or weeks/month/year/etc)
THEN
ACTUAL result: a spike on the same XAxis coordinate is rendered from 100 to 200 USD
EXPECTED result: a single point of 300 USD is rendered

Screenshot 2024-01-02 at 15 43 42
Screenshot 2024-01-02 at 15 57 19

I've tried in this REPL
https://codesandbox.io/s/friendly-snyder-e8kcd

Here is my dataset
```
const values = [
{
x: new Date("2020-01-01 15:00"),
y: 100.2,
},
{
x: new Date("2020-01-01 16:00"),
y: 200.2,
},
{
x: new Date("2020-01-02"),
y: 102.2,
},
{
x: new Date("2020-01-03"),
y: 105.3,
},
{
x: new Date("2020-01-11"),
y: 104.4,
},
];
```

### Possible Implementation

As a workaround, the users are forced to process the dataset and resolve such collisions before feeding the data to ChartJS.
However, i cant imagine an example of a domain where such kind of accumulation would be unwanted.
Even so, having an option to enable such accumulation out of box would be a nice addition to ChartJS greatness.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.