I'm trying to style a chart using chart.js but I can't figure out how to disable the legends. At the same time I want to use the generateLegend() to style the legends somewhere else on the page. So I just want to disable the legends inside the canvas element. Can you guys help me?
Here's my code:
canvas id="myChart"></canvas>
<div id="legendq3"></div>
<script>
var ctx = document.getElementById("myChart");
var data = {
labels: [
"Red",
"Green",
"Yellow"
],
datasets: [
{
data: [300, 50, 100],
backgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56"
],
hoverBackgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56"
]
}]
};
var options = {
legendTemplate :'<ul>'
+'<% for (var i=0; i<datasets.length; i++) { %>'
+'</li>'
+'<span style=\"background-color:<%=datasets[i].lineColor%>\"></span>'
+'<% if (datasets[i].label) { %><%= datasets[i].label %><% } %>'
+'</li>'
+'</ul>'
}
var myDoughnutChart = new Chart(ctx, {
type: 'doughnut',
data: data,
options: options
});
document.getElementById('legendq3').innerHTML = myDoughnutChart.generateLegend();
</script>