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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<script>
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
title:{
text: "Customer Complaints"
},
axisY: {
title: "Number of Reviews",
lineColor: "#4F81BC",
tickColor: "#4F81BC",
labelFontColor: "#4F81BC",
gridThickness: 0
},
axisY2: {
title: "Percent",
suffix: "%",
gridThickness: 0,
lineColor: "#C0504E",
tickColor: "#C0504E",
labelFontColor: "#C0504E"
},
data: [{
type: "column",
dataPoints: [
{ label: "Parking", y: 3050 },
{ label: "Rude Sales Rep.", y: 1100 },
{ label: "Poor Lighting", y: 850 },
{ label: "Confusing Layout", y: 480 },
{ label: "Limited Size", y: 350 },
{ label: "Faded Clothes", y: 180 },
{ label: "Shrank Clothes", y: 120 }
]
}]
});
chart.render();
createPareto();
function createPareto(){
var dps = [];
var yValue, yTotal = 0, yPercent = 0;
for(var i = 0; i < chart.data[0].dataPoints.length; i++)
yTotal += chart.data[0].dataPoints[i].y;
for(var i = 0; i < chart.data[0].dataPoints.length; i++) {
yValue = chart.data[0].dataPoints[i].y;
yPercent += (yValue / yTotal * 100);
dps.push({label: chart.data[0].dataPoints[i].label, y: yPercent });
}
chart.addTo("data", {type:"line", axisYType: "secondary", yValueFormatString: "0.##'%'", indexLabel: "{y}", indexLabelFontColor: "#C24642", dataPoints: dps});
chart.axisY[0].set("maximum", yTotal, false);
chart.axisY2[0].set("maximum", 105, false );
chart.axisY2[0].set("interval", 25 );
}
}
</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>