HTMLcopy
1
<label><input onclick="switchChart(treemap)" type="radio" name="type" checked>Treemap</label>
2
<label><input onclick="switchChart(sunburst)" type="radio" name="type">Sunburst</label>
3
<label><input onclick="switchChart(gantt)" type="radio" name="type">Gantt</label>
4
<div id="container"></div>
CSScopy
16
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
label {
8
display: inline-block;
9
margin: 10px 0 0 10px;
10
}
11
#container {
12
position: absolute;
13
width: 100%;
14
top: 35px;
15
bottom: 0;
16
}
JavaScriptcopy
x
1
var charts = [];
2
var treemap, sunburst, gantt;
3
4
anychart.onDocumentReady(function () {
5
6
// create data
7
var data = [
8
{
9
name: "Root",
10
actualStart: Date.UTC(2018, 0, 25),
11
actualEnd: Date.UTC(2018, 2, 14),
12
children: [
13
{
14
name: "Child 1",
15
value: 65511098,
16
actualStart: Date.UTC(2018, 0, 25),
17
actualEnd: Date.UTC(2018, 1, 3)
18
},
19
{
20
name: "Child 2",
21
value: 64938716,
22
actualStart: Date.UTC(2018, 1, 4),
23
actualEnd: Date.UTC(2018, 1, 4)
24
},
25
{
26
name: "Child 3",
27
value: 59797978,
28
actualStart: Date.UTC(2018, 1, 4),
29
actualEnd: Date.UTC(2018, 1, 24)
30
},
31
{
32
name: "Child 4",
33
value: 46070146,
34
actualStart: Date.UTC(2018, 1, 24),
35
actualEnd: Date.UTC(2018, 2, 14)
36
}
37
]
38
}];
39
40
// create a data tree
41
var treeData = anychart.data.tree(data, "as-tree");
42
43
// create container for all charts
44
var stage = anychart.graphics.create('container');
45
46
// create a treemap chart and set the data
47
treemap = anychart.treeMap(treeData);
48
// set the title
49
treemap.title("Tree Data Model: Basic Sample");
50
// set the container id and draw
51
treemap.container(stage).draw();
52
charts.push(treemap);
53
54
// create a sunburst chart and set the data
55
sunburst = anychart.sunburst(treeData);
56
// set the title
57
sunburst.title("Tree Data Model: Quick Start");
58
// set the container id and draw
59
sunburst.container(stage).draw();
60
sunburst.enabled(false);
61
charts.push(sunburst);
62
63
64
// create a gantt chart
65
gantt = anychart.ganttProject();
66
// set the data
67
gantt.data(treeData);
68
// set the title
69
gantt.title("Tree Data Model: Quick Start");
70
// set the container id and draw
71
gantt.container(stage).draw();
72
// fit elements to the width of the timeline
73
gantt.fitAll();
74
gantt.enabled(false);
75
charts.push(gantt);
76
77
});
78
79
// switch the chart shown
80
function switchChart(chart){
81
for (var i = 0; i < charts.length; i++) {
82
charts[i].enabled(charts[i] === chart);
83
}
84
}