I am trying to change the color of a part of a line chart in chart.js. I followed these posts:
How to change line segment color of a line graph in Chart.js?
And
I am close to achieving the proper result, however, the second line does not want to begin at the end of the first one.
Here is the code that is problematic:
var myChart5 = new Chart(ctx5, {
type: 'line',
data: {
labels: document.getElementById('tag4').textContent == 'ITEMS IN DIFFICULTY' ?
['90 days backward','60 days backward','30 days backward','30 days forward'] :
['90 days backward','60 days backward','30 days backward','30 days forward'],
datasets: [{
labels: labels8,
data: defaultData8,
fill: true,
backgroundColor: ['rgba(54, 162, 235, 0.2)'],
borderColor: ['rgba(255, 99, 132, 1)'],
borderWidth: 1
}, {
label: labels18,
data: defaultData18,
fill: true,
backgroundColor: ['rgba(255, 99, 132, 0.2)'],
borderColor: ['rgba(255, 99, 132, 1)'],
borderWidth: 1
}],
options: {
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Quantity Sold'
},
ticks: {
min: 0
}
}]
}
}
}
});
And here is what the data looks like:
"labels8": [
"90_days_backward",
"60_days_backward",
"30_days_backward"
],
"default8": [
129259.0,
149651.0,
70699.0
],
"labels18": [
"30_days_backward",
"30_days_forward"
],
"default18": [
70699.0,
109145.6
]
I am a bit confused about how to proceed, I have tried include "NaN" values in the second dataset to push it forward but it won't make the trick. Would someone has a clue on how to fix this problem?