I'd like to disable the built-in legends (the colored rectangles) in my chart. Ad the same time I want to keep the custom legends I created with :document.getElementById('legendq3').innerHTML = myDoughnutChart.generateLegend();
<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
});
//myDoughnutChart.defaults.global.legends.display = false;
document.getElementById('legendq3').innerHTML = myDoughnutChart.generateLegend();
</script>
I found only this solution. Add this to options
legend: {
display: false,
}
Here is an example http://jsfiddle.net/qy1hr7mx/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With