Chartjs-Piechart doesn't show up in Canvas

1👍

Take a look at the fiddle – Pie chart with Chart.js
I made the following changes:-

var pieChartCanvas = $("#myChart").get(0).getContext("2d");
var pieChart = new Chart(pieChartCanvas);
pieChart.Pie(data, options);

0👍

From the example you gave it looks like the syntax has changed too.

It should be

var myPieChart = new Chart(ctx).Pie(data);

Not

var myPieChart = new Chart(ctx, {
    type: "pie",
    data: data,
    options: options
});

Got that from the example found in the docs -> https://github.com/nnnick/Chart.js/blob/master/samples/pie.html

0👍

They also changed the data format in 2.0. If you checkout the sample here. You’ll see the data is like this now:

data: {
        datasets: [{
            data: [
               ...
            ],
            backgroundColor: [
               ...
            ]
        }/* notice you can have more than one dataset, with pie they interlace when you have more than one */],
        labels: [
            ...
        ]
    }

Hope that helps…. also I needed to pull the v2.0-dev branch and build it myself to get past one bug that I found in the “released” version, so you may have better luck with that!

Leave a comment