Chart.js: [BUG] labelOpts undefined

on line 11546 in dist of 2.7.1:

var fontSize = valueOrDefault(labelOpts.fontSize, globalDefault.defaultFontSize);

labelOpts is undefined.

I just followed the basic getting started:

http://www.chartjs.org/docs/latest/getting-started/usage.html

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments

@sweatherall I don’t support you’re using a premade template on your site? Maybe something like Gentelella? I was having the same problem. Stumped me for hours. Turns out the template had an initialization routine that overwrote the label option completely. Do a search in your project for Chart.defaults.global and see if you get any hits.

@scooter12 woooow, im using Gentellela template, and thats the issue, thanks a lot!

I think @Pimnr47 has some code that sets the legend.labels option to something undefined. Maybe as the result of some function.

Example to trigger issue

var ctx = document.getElementById("myChart");
var legendOptions = {};
var myChart = new Chart(ctx, {
    type: 'bar',
    data: {
        labels: ["One", "Two", "Three", "Four", "Five", "Six"],
        datasets: [{
            label: '# of Votes',
            data: [12, 19, 3, 5, 2, 3],
        }]
    },
    options: {
        legend: {
            labels: legendOptions.labels
        },
    }
});

To prevent any such cases being reported in the future I think the configuration should be sanitized before being merged with the defaults, or warn the user with console.warn.