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 data
4
var data = [
5
{
6
id: "1",
7
name: "Development",
8
actualStart: 1515974400000,
9
actualEnd: 1520640000000,
10
children: [
11
{
12
id: "1_1",
13
name: "Analysis",
14
actualStart: 1515974400000,
15
actualEnd: 1516838400000
16
},
17
{
18
id: "1_2",
19
name: "Design",
20
actualStart: 1516406400000,
21
actualEnd: 1517702400000
22
},
23
{
24
id: "1_3",
25
name: "Meeting",
26
actualStart: 1517788800000,
27
actualEnd: 1517788800000
28
},
29
{
30
id: "1_4",
31
name: "Implementation",
32
actualStart: 1517788800000,
33
actualEnd: 1519430400000
34
},
35
{
36
id: "1_5",
37
name: "Testing",
38
actualStart: 1519516800000,
39
actualEnd: 1520640000000
40
}
41
]}
42
];
43
44
// create a data tree
45
var treeData = anychart.data.tree(data, "as-tree");
46
47
// create a chart
48
var chart = anychart.ganttProject();
49
50
// set the data
51
chart.data(treeData);
52
53
// configure the first data grid column
54
column_1 = chart.dataGrid().column(0);
55
column_1.setColumnFormat("id", "text");
56
column_1.title("text");
57
column_1.title().fontSize(10);
58
59
// configure the second data grid column
60
column_2 = chart.dataGrid().column(1);
61
column_2.setColumnFormat("id", "short-text");
62
column_2.title().useHtml(true);
63
column_2.title("short-text");
64
column_2.title().fontSize(10);
65
column_2.depthPaddingMultiplier(0);
66
column_2.collapseExpandButtons(false);
67
68
// add and configure the third data grid column
69
column_3 = chart.dataGrid().column(2);
70
column_3.setColumnFormat("id", "direct-numbering");
71
column_3.title().useHtml(true);
72
column_3.title("direct-numbering");
73
column_3.title().fontSize(10);
74
column_3.title().wordWrap("break-word");
75
column_3.title().padding(7);
76
77
// set the position of the splitter
78
chart.splitterPosition("50%");
79
80
// configure the scale
81
chart.getTimeline().scale().maximum("2018-03-15");
82
83
// set the container id
84
chart.container("container");
85
86
// initiate drawing the chart
87
chart.draw();
88
89
// fit elements to the width of the timeline
90
chart.fitAll();
91
});