HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// create data
4
var data = [
5
{x: "John", value: 5000},
6
{x: "Richard", value: 5000},
7
{x: "Larry", value: 5000},
8
{x: "Marta", value: 15000}
9
];
10
11
//create a chart and set the data
12
chart = anychart.pie(data);
13
14
// enable html for the legend
15
chart.legend().useHtml(true);
16
17
// configure the format of legend items
18
chart.legend().itemsFormat(function() {
19
var point = chart.getPoint(this.index);
20
var maxPoint = chart.getStat("max");
21
var percent = point.getStat("percentValue").toFixed(1);
22
if (point.get("value") == maxPoint) {
23
return "<span style='color:#455a64;font-weight:600'>" +
24
this.x + ": " + percent + "%</span>";
25
} else {
26
return this.x + "</span>: " + percent + "%";
27
}
28
});
29
30
// set the chart title
31
chart.title("Legend Items: Text Format (Formatting Functions)" +
32
"\nSingle Series");
33
34
// set the container id
35
chart.container("container");
36
37
// initiate drawing the chart
38
chart.draw();
39
});