HTMLcopy
1
<button onclick="switchMode()">Switch labels display mode</button>
2
<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
var chart;
2
anychart.onDocumentReady(function () {
3
4
// create data
5
var data = [
6
{name: "Root 1", children: [
7
{name: "Leaf 1", value: 150000000},
8
{name: "Leaf 2", value: 150000000},
9
{name: "Leaf 3", value: 150000000}
10
]},
11
{name: "Root 2", children: [
12
{name: "Leaf 1", value: 150000000},
13
{name: "Leaf 2", value: 150000000},
14
{name: "Leaf 3", value: 150000000}
15
]}
16
];
17
18
// create a chart and set the data
19
chart = anychart.circlePacking(data, "as-tree");
20
21
// set the chart title
22
chart.title().useHtml(true);
23
chart.title("Circle Packing: Labels and Tooltips (Labels mode)");
24
25
// set the container id
26
chart.container("container");
27
28
// initiate drawing the chart
29
chart.draw();
30
});
31
32
// circle packing chart labels switching function
33
function switchMode(){
34
if (chart.labelsMode()=='leaves') {
35
chart.labelsMode('roots');
36
} else {
37
chart.labelsMode('leaves');
38
}
39
}