Adding title to legends on positioning it to the top
HTML5 & JS Pie Charts - 1 | JSFiddle Sample Code
HTML
<script src="https://cdn.canvasjs.com/canvasjs.min.js"></script>
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
<script src="https://cdn.canvasjs.com/canvasjs.min.js"></script>
JavaScript
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer",{
theme: "light2",
title: { text: "Programming Language Popularity", margin: 20 },
subtitles: [{
text: "Language Shares",
//horizontalAlign: "left" // uncomment this to try out different positions
}],
legend: {
verticalAlign: "top",
//horizontalAlign: "left" // uncomment this to try out different positions
},
data: [{
type: "pie",
showInLegend: true,
indexLabel: "{name} - {y}%",
legendText: "{name}",
dataPoints: [
{ y: 25.3, name: "Python" },
{ y: 20.1, name: "JavaScript" },
{ y: 15.7, name: "Java" },
{ y: 12.4, name: "C#" },
{ y: 10.5, name: "TypeScript" },
{ y: 16.0, name: "Others" }
]
}]
});
chart.render();
}