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
{id:"1_3", start: "2018-03-03", end: "2018-03-25"}
12
]},
13
{
14
id: "2",
15
name: "Resource",
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: "Resource",
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-table");
30
31
// create a chart
32
var chart = anychart.ganttResource();
33
34
// set the data
35
chart.data(treeData);
36
37
// configure labels of periods
38
chart.getTimeline().periods().labels().enabled(true);
39
chart.getTimeline().periods().labels().format("period");
40
chart.getTimeline().periods().labels().fontColor("black");
41
42
// set the container id
43
chart.container("container");
44
45
// initiate drawing the chart
46
chart.draw();
47
48
// fit elements to the width of the timeline
49
chart.fitAll();
50
});