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: "Server 1",
8
periods: [
9
{id:"1_1", start: "2018-01-05", end: "2018-01-25"},
10
{id:"1_2", start: "2018-01-28", end: "2018-02-22"},
11
{id:"1_3", start: "2018-03-03", end: "2018-03-25"}
12
]},
13
{
14
id: "2",
15
name: "Server 2",
16
periods: [
17
{id: "2_1", start: "2018-01-07", end: "2018-02-15"},
18
{id: "2_2", start: "2018-02-26", end: "2018-03-20"}
19
]},
20
{
21
id: "3",
22
name: "Server 3",
23
periods: [
24
{id: "3_1", start: "2018-01-04", end: "2018-03-25"}
25
]}
26
];
27
28
// create a data tree
29
var treeData = anychart.data.tree(data, "as-tree");
30
31
// create a chart
32
var chart = anychart.ganttResource();
33
34
// set the data
35
chart.data(treeData);
36
37
// create and configure a custom data grid column
38
var newColumn = chart.dataGrid().column(2);
39
newColumn.width(90);
40
newColumn.title("Start");
41
newColumn.title().fontColor("#64b5f6");
42
newColumn.title().fontWeight(600);
43
newColumn.labels().fontColor("#64b5f6");
44
newColumn.labels().format("{%start}{dateTimeFormat:dd MMM}");
45
46
// set the position of the splitter
47
chart.splitterPosition("42%");
48
49
// set the container id
50
chart.container("container");
51
52
// initiate drawing the chart
53
chart.draw();
54
55
// fit elements to the width of the timeline
56
chart.fitAll();
57
});