chartjs / chartjs/Chart.js

Instructions for adding data to a chart do not work for time series data.

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

Description

### Documentation Is:

- [X] Missing or needed?
- [ ] Confusing
- [ ] Not sure?

### Please Explain in Detail...

The docs show this example for updating the data in a chart
```js
function addData(chart, label, newData) {
chart.data.labels.push(label);
chart.data.datasets.forEach((dataset) => {
dataset.data.push(newData);
});
chart.update();
}
```
However when I attempted to add data to my chart this way it did not work.

The charts I am using show time series data, I belive the issue is that when the scale type is set to `"time"` chart.js does not store the scale values in `chart.data.labels`. To get around this I had to change the format of the data I was passing in to look like `{x:Date, y:number}`. This was not mentioned anywhere in the docs and I had to discover it through trial and error.

### Your Proposal for Changes

I am not sure on where the best place to mention this in the docs would be but my first guess would be the https://www.chartjs.org/docs/latest/developers/updates.html page.

### Example

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYQBYENZwL5wGZQQhwDkAxhrAHQBWAziQNwCwAUAG6ZwAm6M6cALxwA2gEYATABo4YgJwyAzDICsM6XEUBdNgHpde3XACScDOwCmcAHYQ4wbhYHA8cAOYXrFqH2DW3cDCoFnRWvDAhgajAdHAA7ugAnvHAADap8dAA1ilBEACu8ALhVui8YBFQhmycUHBkMAAeQjwQZPkgnjBUHjAAoqkWndYwAEKJxtwAFABEIIlomDAzAJRw6LEAEgAqALIAMsjo1px0A0NdLKz6hnAAIhCRtvBx2dUcXPOLWMJecSiUGBTBqNGQINhwSGBRJgCwALlIqT8FhIUghUPC6AR4NYULxcFS6AARhZUnQEZiqCB0GAplMAPpSYArQQAPnufAsVFscSmKyonFS+QsAHk8Hy4ABaOBTYBwABUcAAbAAGNVrFZo3H4yGY0IwcmiHE6nWEkmpBEkADEcAgrgAahAIgwtSb8ZiKXx0K6TdgdNrIdgfZCIBVgBBrIbjfi6GR0IMo+idY1sUmTTAYfC4DMYKALDNg+m86mA264PlrMAYAiZqgClAC2mddgm1Cg63IYkS2W4B2cK2W6XB9gVldbgB1bIWbj4aBwTq9j51L6AiQtP4ApbAppgtMZ2GWpFeVFpj2IPtm0mGwt4vUWA0IkTRnuXi2kG12uCO50n0tus+UtStJTOwTIsuyCBQPe+RQNYiApncnLchAvL8oKwpihK0qygqypqiqmpwF27A4CON5tv6eLtqWoa5hGiZ-nAsbxiE3Ymim56MXi+5ZjmeaNlxUK5p0bE9hWVY1nWMECT2g5utRbpdpxPZ9nJ+JqYGbAjowQA

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.