Chartjs-Multiple dynamic vertical lines on a chart with Chart.js

0👍

If I understand it right, you can loop through the dates array and build the treatments array with a for loop.

I’ve not run it, but the below should at least point you in the right direction – it assumes there are the same number of colours as dates.

var dates = ["01/03/2018", "01/05/2018", "09/10/2018"];
var colours = ["#000", "#000", "#fff"];
var treatments = [];
var i;
for (i = 0; i < dates.length; i++) {
    treatments.push({
                  type: 'line',
                  mode: 'vertical',
                  scaleID: 'x-axis-0',
                  value: dates[i],
                  borderColor: colours[i],
                  borderWidth: 4,
                  label: {
                    enabled: true,
                    content: '13/07/2018'
                  }
      });
}

Leave a comment