0๐
I also encountered this problem recently and solved it using a solution similar to yours.
Unfortunately in Chart.js there is no easy way to set the chart background color based on the zone.
Solution.
The solution I adopted was to create a dataset for each color I wanted to
use in the chart.
Another solution that I tried but was less satisfying is to create a bar chart, whose height of the bars was equal to the height of the chart so I could color the entire area.
- Chartjs-Chart.js โ Line data on the chart do not match their dates
- Chartjs-Bind first property value of an array of object into chart.js
Source:stackexchange.com