54 lines
1.3 KiB
HTML
Executable File
54 lines
1.3 KiB
HTML
Executable File
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<script>
|
|
window.onload = function () {
|
|
|
|
var chart = new CanvasJS.Chart("chartContainer", {
|
|
animationEnabled: true,
|
|
exportEnabled: true,
|
|
title:{
|
|
text: "Sales via Advertisement"
|
|
},
|
|
data: [{
|
|
type: "funnel",
|
|
reversed: true,
|
|
showInLegend: true,
|
|
legendText: "{label}",
|
|
indexLabel: "{label} - {y}",
|
|
toolTipContent: "<b>{label}</b>: {y} <b>({percentage}%)</b>",
|
|
indexLabelFontColor: "black",
|
|
dataPoints: [
|
|
{ y: 3500, label: "Impressions" },
|
|
{ y: 2130, label: "Clicked" },
|
|
{ y: 1950, label: "Free Downloads" },
|
|
{ y: 500, label: "Purchase" },
|
|
{ y: 300, label: "Renewal" }
|
|
]
|
|
}]
|
|
});
|
|
calculatePercentage();
|
|
chart.render();
|
|
|
|
function calculatePercentage() {
|
|
var dataPoint = chart.options.data[0].dataPoints;
|
|
var total = dataPoint[0].y;
|
|
for(var i = 0; i < dataPoint.length; i++) {
|
|
if(i == 0) {
|
|
chart.options.data[0].dataPoints[i].percentage = 100;
|
|
} else {
|
|
chart.options.data[0].dataPoints[i].percentage = ((dataPoint[i].y / total) * 100).toFixed(2);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
</script>
|
|
<script src="../../canvasjs.min.js"></script>
|
|
</head>
|
|
<body>
|
|
<div id="chartContainer" style="height: 370px; max-width: 920px; margin: 0px auto;">
|
|
</div>
|
|
</body>
|
|
</html> |