Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 3 tasks
kerstop opened this issue Sep 7, 2024 · 0 comments
Open
1 of 3 tasks

Comments

@kerstop
Copy link

kerstop commented Sep 7, 2024

Documentation Is:

  • Missing or needed?
  • Confusing
  • Not sure?

Please Explain in Detail...

The docs show this example for updating the data in a chart

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant