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 a chart and set the data
4
var chart = anychart.pyramid([
5
{name: "Fantasy", value: 637166, custom_field: "info 1"},
6
{name: "Science Fiction", value: 721630, custom_field: "info 2"},
7
{name: "Detective", value: 148662, custom_field: "info 3"},
8
{name: "Classics", value: 78662, custom_field: "info 4"},
9
{name: "Textbooks", value: 90000, custom_field: "info 5"}
10
]);
11
12
// enable HTML for labels and tooltips
13
chart.labels().useHtml(true);
14
chart.tooltip().useHtml(true);
15
16
// configure labels
17
chart.labels().format(function() {
18
var percentOfTotal = (this.getData("value")*100)/this.getStat("sum");
19
if (percentOfTotal > 40)
20
return "<span style='color:#dd2c00;font-weight:bold'>" +
21
this.name + ": " + percentOfTotal.toFixed(1) + "%</span>";
22
return this.name + ": " +percentOfTotal.toFixed(1) + "%";
23
});
24
25
// configure tooltips
26
chart.tooltip().format(function() {
27
var percentOfTotal = (this.getData("value")*100)/this.getStat("sum");
28
if (percentOfTotal > 40)
29
return "<span style='font-size:18'>" +
30
percentOfTotal.toFixed(1) + "% (" +
31
this.value + ")</span><br><br>" +
32
this.getData("custom_field");
33
return percentOfTotal.toFixed(1) + "% (" + this.value +
34
")<br><br>" + this.getData("custom_field");
35
});
36
37
// draw chart
38
chart.container("container");
39
chart.draw();
40
});