1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<script>
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
theme: "light2", //"light1", "dark1", "dark2"
title:{
text: "Sales Analysis - June 2016"
},
data: [{
type: "funnel",
indexLabelPlacement: "inside",
indexLabelFontColor: "white",
toolTipContent: "<b>{label}</b>: {y} <b>({percentage}%)</b>",
indexLabel: "{label} ({percentage}%)",
dataPoints: [
{ y: 1400, label: "Leads" },
{ y: 1212, label: "Initial Communication" },
{ y: 1080, label: "Customer Evaluation" },
{ y: 665, label: "Negotiation" },
{ y: 578, label: "Order Received" },
{ y: 549, label: "Payment" }
]
}]
});
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>
</head>
<body>
<div id="chartContainer" style="height: 370px; max-width: 920px; margin: 0px auto;"></div>
<script src="../../asset/js/canvasjs/canvasjs.min.js"></script>
</body>
</html>