I'm using ChartJs and all works fine.
I now need to add a legend and ran into an issue! The legend never shows.
I have seen How can labels/legends be added for all chart types in chart.js (chartjs.org)? and can confirm that I have the current latest version (version 1.0.2)
I ran Chrome dev tools and realised that the reason the legend doesn't show is because an exception is being thrown (pie chart still shows). The error message is
Uncaught ReferenceError: datasets is not defined
This is the code I'm using for my PieChart
//data copied direct from the ChartJs docs
data = [
{
value: 300,
color:"#F7464A",
highlight: "#FF5A5E",
label: "Red"
},
{
value: 50,
color: "#46BFBD",
highlight: "#5AD3D1",
label: "Green"
}
];
ctx = $("#adwordsPieChart").get(0).getContext("2d");
var myPieChart = new Chart(ctx).Pie(data, chartOptions);
var legendAdwordsVsOrganic = myPieChart.generateLegend();
document.getElementById("adwordVsOrganicLegend").innerHTML = legendAdwordsVsOrganic;
I checked the same issue occurs in IE and Chrome, and it does.
I don't know how to fix this. I have followed the instructions (I think). Any ideas?
chartOptions- ThePavolC