[Chartjs]-Cannot read property 'labels' of undefined

5๐Ÿ‘

โœ…

I found my error!
The the creation of the radar comes at the top of the code before I declare any of the data or options.

var myRadarChart = new Chart(ctx).Radar(data, options);

This line must be placed at the bottom of the function

$(function () {
            var ctx = $('#myCanv').get(0).getContext("2d");
            var data = {
                labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
                datasets: [
                    {
                        label: "My First dataset",
                        fillColor: "rgba(220,220,220,0.2)",
                        strokeColor: "rgba(220,220,220,1)",
                        pointColor: "rgba(220,220,220,1)",
                        pointStrokeColor: "#fff",
                        pointHighlightFill: "#fff",
                        pointHighlightStroke: "rgba(220,220,220,1)",
                        data: [65, 59, 90, 81, 56, 55, 40]
                    },
                    {
                        label: "My Second dataset",
                        fillColor: "rgba(151,187,205,0.2)",
                        strokeColor: "rgba(151,187,205,1)",
                        pointColor: "rgba(151,187,205,1)",
                        pointStrokeColor: "#fff",
                        pointHighlightFill: "#fff",
                        pointHighlightStroke: "rgba(151,187,205,1)",
                        data: [28, 48, 40, 19, 96, 27, 100]
                    }
                ]
            };
         var myRadarChart = new Chart(ctx).Radar(data, options);
        });

Leave a comment