With any instance of Chart, just invoke the method .generateLegend()
:
<!DOCTYPE html>
<html>
<head></head>
<body>
<canvas id="mychart"></canvas>
<div id="legenda"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.js">
</script>
<script type="text/javascript">
var data = [
{
value: 300,
color:"#F7464A",
highlight: "#FF5A5E",
label: "Red"
},
{
value: 50,
color: "#46BFBD",
highlight: "#5AD3D1",
label: "Green"
},
{
value: 100,
color: "#FDB45C",
highlight: "#FFC870",
label: "Yellow"
}
];
var ctx = document.getElementById("mychart").getContext("2d");
var myPieChart = new Chart(ctx).Pie(data);
// Legenda
document.getElementById('legenda').innerHTML = myPieChart.generateLegend();
</script>
</body>
</html>
Most likely you will also want to change the caption HTML/template, so you should pass, via options
for Chart the property legendTemplate
with the respective template.
The syntax is:
myChart.generateLegend();
– felipsmartins