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 the data
4
let data = anychart.data.set([
5
["Chennai Super Kings", 5, "CSK"],
6
["Mumbai Indians", 5, "MI"],
7
["Kolkatta Knight Riders", 2, "KKR"],
8
["Deccan Chargers", 1, "DC"],
9
["Gujarat Titans", 1, "GT"],
10
["Rajasthan Royal", 1, "RR"],
11
["Sunrisers Hyderabad", 1, "SRH"]
12
]);
13
14
// create a pie chart with the data, naming the values in the dataset
15
let chart = anychart.pie(data.mapAs({name: 0, value: 1, abbr: 2}));
16
17
// create a custom palette
18
let palette = anychart.palettes.distinctColors();
19
// set the colors according to the team brands
20
palette.items([
21
{color: "#004f91"},
22
{color: "#fcce06"},
23
{color: "#3a225d"},
24
{color: "#9a1c22"},
25
{color: "#254aa5"},
26
{color: "#D9E3EF"},
27
{color: "#02183c"}
28
]);
29
// set the palette to the chart
30
chart.palette(palette);
31
32
// configure the labels
33
chart
34
.labels()
35
.format("{%abbr} — {%value}")
36
.fontSize(14)
37
.position("outside");
38
39
// disable the chart legend
40
chart.legend(false);
41
42
// format the tooltip
43
chart
44
.tooltip()
45
.format("Percent of total wins: {%PercentValue}{decimalsCount: 1}%");
46
47
// set chart title text settings
48
chart
49
.title()
50
.enabled(true)
51
.useHtml(true)
52
.text(
53
'<span style = "color: #111; font-size:20px; margin-bottom:10px; dy:20px">IPL Winnership Over 16 Seasons</span>' +
54
'<br/><span style="color:#173685; font-size: 15px;">Among the 10 current IPL teams, 2 dominate, and 3 have never won the title</span>'
55
);
56
57
// set container id for the chart
58
chart.container("container");
59
60
// initiate chart drawing
61
chart.draw();
62
63
});