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
var data = anychart.data.set([
5
["Wimbledon", 8],
6
["Australian Open", 6],
7
["U.S. Open", 5],
8
["French Open", 1]
9
]);
10
11
// create a color palette
12
var palette = anychart.palettes.distinctColors();
13
14
// add the colors according to the brands
15
palette.items([
16
{ color: "#563783" },
17
{ color: "#1b8cca" },
18
{ color: "#022789" },
19
{ color: "#d35220" }
20
]);
21
22
// create a pie chart instance with the passed data
23
var chart = anychart
24
.pie(data)
25
// set the inner radius to make a donut chart
26
.innerRadius("50%")
27
// set the color palette
28
.palette(palette);
29
30
// set the position of the labels
31
chart.labels().format("{%x}: {%y}").fontSize(14);
32
33
// disable the legend
34
chart.legend(false);
35
36
// set the fill when selected
37
chart.selected().fill("#007247");
38
39
// customize the outline when selected
40
chart
41
.selected()
42
.outline()
43
.fill(function () {
44
return anychart.color.lighten("#007247", 0.55);
45
});
46
47
// create a standalone label
48
var label = anychart.standalones.label();
49
50
label
51
.useHtml(true)
52
.text(
53
'<span style = "color: #313136; font-size:18px;">Total titles: 20</span>' +
54
'<br><br><span style = "color: #313136; font-size:18px;">Total finals: 41</span>'
55
)
56
.position("center")
57
.anchor("center")
58
.hAlign("center")
59
.vAlign("middle");
60
61
label.width("100%");
62
label.height("100%");
63
64
// set the label as the center content
65
chart.center().content(label);
66
67
// format the tooltip
68
chart.tooltip().format("Percent of total wins: {%PercentValue}%");
69
70
// set the chart title
71
chart
72
.title()
73
.enabled(true)
74
.useHtml(true)
75
.text(
76
'<span style = "color: #111; font-size:20px; margin-bottom:10px; dy:20px">Grand Slam Titles Won by Roger Federer</span>' +
77
'<br/><span style="color:#007247; font-size: 15px;">The French Open (Roland-Garros) is apparently his least favorite major</span>'
78
);
79
80
// set the container id for the chart
81
chart.container("container");
82
83
// draw the resulting chart
84
chart.draw();
85
86
});