[Chartjs]-How to put function in ChartJS data structures?

0๐Ÿ‘

โœ…

I found the solution by myself.

I put the JSON object in a function, put an AddEventListener("click", function()), targeted the part of the JSON to modify and added an update() at the end.

function chartFunction() {
   ....
   // data before
   datasets: [
       {
         label: "Exemple",
         data: [
           { x: "Day1", y: 0 },
   .....


       button.addEventListener("click", () => {
       (myChart.data.datasets[0].data = [...]).myChart.update();
       });
};

chartFunction();

Leave a comment