HTMLcopy
1
<div id="container"></div>
CSScopy
8
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// add data
4
let data = [
5
{ x: "Managing the loan or lease", value: 15265 },
6
{ x: "Problems when you are unable to pay", value: 7678 },
7
{ x: "Taking out the loan or lease", value: 4370 },
8
{ x: "Shopping for a loan or lease", value: 2029 },
9
{ x: "Managing the line of credit", value: 806 },
10
{ x: "Other issues", value: 1427 }
11
];
12
13
// create a pareto chart with the data
14
let chart = anychart.pareto(data);
15
16
// set a pareto column series
17
let column = chart.getSeriesAt(0);
18
// customize the column colors
19
// fill
20
column.fill(function () {
21
if (this.rf < 10) {
22
return "#b5cfa8";
23
}
24
return "#57c478";
25
});
26
// stroke
27
column.stroke(function () {
28
if (this.rf < 10) {
29
return "#b5cfa8 ";
30
}
31
return "#57c478";
32
});
33
34
// set a pareto line series
35
let line = chart.getSeriesAt(1);
36
// customize the line stroke
37
line.stroke("#c04d3b");
38
39
// name the measure axis
40
chart.yAxis(0).title("Issue frequency");
41
// name the cumulative percentage axis
42
chart.yAxis(1).title("Cumulative percentage");
43
44
// customize the column label format
45
column.labels().enabled(true).format("{%RF}%");
46
47
// customize the tooltip format
48
// column series
49
column.tooltip().format("Value: {%Value}");
50
// line series
51
line.tooltip().format("Cumulative frequency: {%CF}% \n Relative frequency: {%RF}%");
52
53
// set the tick interval
54
chart.yAxis(1).scale().ticks().interval(10);
55
56
// create the first horizontal line marker
57
chart
58
.lineMarker(0)
59
.axis(chart.yAxis(1))
60
.value(20)
61
.stroke("#A5B3B3", 1, "10 2", "round");
62
63
// create the second horizontal line marker
64
chart
65
.lineMarker(1)
66
.axis(chart.yAxis(1))
67
.value(80)
68
.stroke("#A5B3B3", 1, "10 2", "round");
69
70
// add a crosshair
71
chart.crosshair().enabled(true).xLabel(false);
72
73
// enable the stagger mode for the x-axis labels
74
chart.xAxis().staggerMode(true);
75
// configure the stagger mode
76
chart.xAxis().staggerLines(2);
77
78
// add a chart title
79
chart
80
.title()
81
.enabled(true)
82
.useHtml(true)
83
.text(
84
'<span style = "color: #111; font-size:20px; margin-bottom:10px; dy:20px">Consumer Loan Customer Complaints (CFPB)</span>' +
85
'<br/><span style="color:#57c478; font-size: 15px;">The top 2 issues make up almost 80% of all the issues identified in consumer complaints</span>'
86
);
87
88
// set the container element id for the chart
89
chart.container("container");
90
91
// initiate the pareto chart drawing
92
chart.draw();
93
94
});