HTMLcopy
1
<button onclick="drillToItem()">Drill Down to Technical</button>
2
<button onclick="drillUpALevel()">Drill Up 1 Level</button>
3
<div id="container"></div>
CSScopy
15
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
button {
8
margin: 10px 0 0 10px;
9
}
10
#container {
11
position: absolute;
12
width: 100%;
13
top: 35px;
14
bottom: 0;
15
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// create data
4
var data = [
5
{name: "Company A", children: [
6
{name: "Technical", children: [
7
{name: "Team Leaders"},
8
{name: "Architects"},
9
{name: "Developers"},
10
{name: "Testers"}
11
]},
12
{name: "Sales", children: [
13
{name: "Analysts"},
14
{name: "Executives"}
15
]},
16
{name: "HR"},
17
{name: "Management"}
18
]}
19
];
20
21
// create a data tree
22
treeData = anychart.data.tree(data, "as-tree");
23
24
// create a chart and set the data
25
chart = anychart.sunburst(treeData);
26
27
/* listen to the chartDraw event
28
and add the drilldown path to the chart title */
29
chart.listen("chartDraw",function() {
30
// get the drilldown path and convert it to a string
31
var text = printPath(chart.getDrilldownPath());
32
// set the chart title
33
chart.title().useHtml(true);
34
chart.title("Sunburst: Interactivity (Drilling Down and Up)<br><br>" +
35
"Path: <span style = 'color:#990000; font-style:italic'>" + text +
36
"</span><br><br><span style='font-size:12; font-style:italic'>" +
37
"Corporate Structure</span>");
38
});
39
40
// set the container id
41
chart.container("container");
42
43
// initiate drawing the chart
44
chart.draw();
45
});
46
47
/* convert the current drilldown path to a string */
48
function printPath(path) {
49
/* go through the array of data items
50
and use the get() method to obtain the "name" field */
51
var text = "";
52
for (i = 0; i < path.length; i++){
53
text += path[i].get("name") + "\\";
54
}
55
return text;
56
}
57
58
// drill down to a data item
59
function drillToItem() {
60
/* locate an item in the data tree
61
and get it as an object */
62
var item = treeData.search("name", "Technical");
63
// drill down to the item
64
chart.drillTo(item);
65
}
66
67
// drill up a level
68
function drillUpALevel() {
69
chart.drillUp();
70
}