[Chartjs]-Chart.js: issue with concatening two line charts

2πŸ‘

βœ…

In order for the second line to start at the end of the first, its data array needs to skip those values. What you can do is fill the second array with null as many times as the first array has values.

In your chart configuration pasted above, in the second dataset, here is how you can assign the data property:

// to start right after the end of the previous line
data: defaultData8.slice().fill(null).concat(defaultData18)

// to start on top of the end of the previous line
data: defaultData8.slice(1).fill(null).concat(defaultData18)

This will copy the first data array (too keep the original intact), override all its values with null, the concatenate it with second like data, then assign it to the data property of the second dataset.

Leave a comment