HTMLcopy
1
<button onclick="addItems()">Add Data</button>
2
<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: "Root", children: [
6
{name: "Child 1", value: 80636124},
7
{name: "Child 2", value: 65511098},
8
{name: "Child 3", value: 64938716}
9
]}
10
];
11
12
// create a data tree
13
treeData = anychart.data.tree(data, "as-tree");
14
15
// create a chart and set the data
16
var chart = anychart.sunburst(treeData);
17
18
// set the chart title
19
chart.title("Tree Data Model: Adding Data");
20
21
// set the container id
22
chart.container("container");
23
24
// initiate drawing the chart
25
chart.draw();
26
});
27
28
var itemCount = 1;
29
30
// add new data
31
function addItems() {
32
//create new data
33
var name_1 = "New Node " + itemCount++;
34
var name_2 = "New Node " + itemCount++;
35
var newData = [
36
{"name": name_1, "value": 10000000},
37
{"name": name_2, "value": 10000000}
38
];
39
// add new data
40
treeData.addData(newData, "as-tree");
41
}