HTML
<!DOCTYPE HTML>
<html>
<head>
<script>
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
theme: "light2", // "light1", "light2", "dark1", "dark2"
title: {
text: "GDP Growth Rate - 2016"
},
axisY: {
title: "Growth Rate (in %)",
suffix: "%",
includeZero: false
},
axisX: {
title: "Countries"
},
legend:{
cursor: "pointer",
fontSize: 16,
itemclick: toggleDataSeries
},
data: [{
type: "column",
showInLegend:true,
name:"Asia",
yValueFormatString: "#,##0.0#\"%\"",
dataPoints: [
{ label: "India", x: 1, y: 7.1 },
{ label: "China", x: 2, y: 6.70 },
{ label: "Indonesia", x: 3, y: 5.00 },
{ label: "Japan", x: 4, y: 1.60 }
]
},
{
type: "column",
showInLegend:true,
name:"Europe",
yValueFormatString: "#,##0.0#\"%\"",
dataPoints: [
{ label: "Germany", x: 5, y: 4.8 },
{ label: "Austria", x: 6, y: 3.7 },
{ label: "Switzerland", x: 7, y: 5.4 },
{ label: "UK", x: 8, y: 1.80 },
]
},
{
type: "column",
showInLegend:true,
name:"North America",
yValueFormatString: "#,##0.0#\"%\"",
dataPoints: [
{ label: "Mexico", x: 9, y: 2.30 },
{ label: "United States", x: 10, y: 1.60 },
]
}]
});
chart.render();
function toggleDataSeries(e){
if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
}
else{
e.dataSeries.visible = true;
}
chart.render();
};
};
</script>
</head>
<body>
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</body>
</html>