1

I have a strange issue with chart-js that whenever my page loads legend didn't show up but whenever I force refreshes the page using ctrl+F5 legend show up.

Legends perfectly worked on mozilla but not on chrome

function RefreshMediaTypeChart(fields, colorCodes, dataValues) {
var ctx = document.getElementById("chartuser");
ctx.height=160; 
var data = {
    labels:
        fields,
    datasets: [{
        data: dataValues,
        backgroundColor: colorCodes,
        hoverBackgroundColor:colorCodes
    }]
};

var canvasDoughnut = new Chart(ctx, {
    type: 'doughnut',
    tooltipFillColor: "rgba(51, 51, 51, 0.55)",
    data: data,
    otpions: {            
       legend:{
           display:true
       }
    }
});

var legend =canvasDoughnut.generateLegend();
}

can someone figure it out why?

piedpiper
  • 520
  • 5
  • 18

2 Answers2

0

try something like this:

datasets: [{
    label: 'Legend Name',
    data: dataValues,
    backgroundColor: colorCodes,
    hoverBackgroundColor:colorCodes
}]
DPS
  • 943
  • 11
  • 22
0

Run your js before the document is ready. You can do this by placing your js on top of your page. But your DOM elements will not be available by doing this.

Jango
  • 1