CanvasJS HTML5 JavaScript Charts
CanvasJS HTML5 JavaScript Charts
HTML
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
JavaScript
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
title:{
text: "Crude Oil Reserves vs Production, 2016"
},
axisY: {
title: "Billions of Barrels",
titleFontColor: "#4F81BC",
lineColor: "#4F81BC",
labelFontColor: "#4F81BC",
tickColor: "#4F81BC"
},
axisY2: {
title: "Millions of Barrels/day",
titleFontColor: "#C0504E",
lineColor: "#C0504E",
labelFontColor: "#C0504E",
tickColor: "#C0504E"
},
toolTip: {
shared: true
},
legend: {
cursor:"pointer",
itemclick: toggleDataSeries
},
data: [{
type: "line",
name: "Proven Oil Reserves (bn)",
legendText: "Proven Oil Reserves",
showInLegend: true,
dataPoints:[
{ label: "Saudi", y: 266.21 },
{ label: "Venezuela", y: 302.25 },
{ label: "Iran", y: 157.20 },
{ label: "Iraq", y: 148.77 },
{ label: "Kuwait", y: 101.50 },
{ label: "UAE", y: 97.8 }
]
},
{
type: "line",
name: "Oil Production (million/day)",
legendText: "Oil Production",
axisYType: "secondary",
showInLegend: true,
dataPoints:[
{ label: "Saudi", y: 10.46 },
{ label: "Venezuela", y: 2.27 },
{ label: "Iran", y: 3.99 },
{ label: "Iraq", y: 4.45 },
{ label: "Kuwait", y: 2.92 },
{ label: "UAE", y: 3.1 }
]
}]
});
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();
}
}