Home > Software design >  Change line to dashed if it is a certain label Chart.js
Change line to dashed if it is a certain label Chart.js

Time:07-15

I am working in Chart.js and have created an area chart with several lines. I want to change a line from solid to dashed if it is equal to a certain label, but I can't figure out how to change the borderDash. I am accessing the label correctly, but like I said, I can't seem to figure out how to access the borderDash property for it. Here is my code for this part so far:

for (i = 0; i < chart.data.datasets.length; i  ) {
        if ((chart.data.datasets[i].label == 'Last Place') || (chart.data.datasets[i].label == 'First Place')) {
            chart.data.datasets[i].options.elements.line.borderDash[1, 3];
        }

    }

    chart.update();

CodePudding user response:

I ended up figuring out the answer to this problem.

for (i = 0; i < chart.data.datasets.length; i  ) {
        if ((chart.data.datasets[i].label == 'Last Place') || (chart.data.datasets[i].label == 'First Place')) {
            chart.data.datasets[i].borderDash = [1, 3];
        }

    }

    chart.update();

CodePudding user response:

Based on documentations you are accessing the borderDash correctly but you do not assign anything to it

chart.data.datasets[i].options.elements.line.borderDash = [1,3]
  • Related