我想禁用图表中的内置图例(彩色矩形)。广告同时我想保留我创建的自定义图例: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>
答案 0 :(得分:2)