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: "Resource",
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
connectTo: "2_1", connectorType: "start-finish"},
12
{id:"1_3", start: "2018-03-01", end: "2018-03-25",
13
connectTo: "2_2", connectorType: "start-start"}
14
]},
15
{
16
id: "2",
17
name: "Resource",
18
periods: [
19
{id: "2_1", start: "2018-01-07", end: "2018-02-15"},
20
{id: "2_2", start: "2018-03-05", end: "2018-03-18",
21
connectTo: "3_2", connectorType: "finish-finish"}
22
]},
23
{
24
id: "3",
25
name: "Resource",
26
periods: [
27
{id: "3_1", start: "2018-01-04", end: "2018-02-20",
28
connectTo: "3_2", connectorType: "finish-start"},
29
{id: "3_2", start: "2018-03-01", end: "2018-03-20"}
30
]}
31
];
32
33
// create a data tree
34
var treeData = anychart.data.tree(data, "as-table");
35
36
// create a chart
37
var chart = anychart.ganttResource();
38
39
// set the data
40
chart.data(treeData);
41
42
// configure labels of periods
43
chart.getTimeline().periods().labels().enabled(true);
44
chart.getTimeline().periods().labels().format("{%start}{dateTimeFormat:MM.dd}");
45
chart.getTimeline().periods().labels().fontColor("black");
46
47
// set the container id
48
chart.container("container");
49
50
// initiate drawing the chart
51
chart.draw();
52
53
// fit elements to the width of the timeline
54
chart.fitAll();
55
});