[Chartjs]-Plot with year-independent date axis – JS

1👍

datais is not an array but an object, hence it has no filter function. You could create the data of individual datasets as follows:

const baseData = {"2022":[["01\/02","6.5"],["01\/03","6.5"],["01\/04","11.0"],["05\/12","887.7"]],"2023":[["12\/05","2.5"],["12\/05","2.5"],["12\/06","10.0"],["12\/06","10.0"]]};

const data = baseData['2022'].map(arr => ({ x: arr[0], y: parseFloat(arr[1])}));
console.log(data );

You can also create all datasets dynamically, similar to what was proposed in this answer: https://stackoverflow.com/a/75635274/2358409.

Leave a comment