HTMLcopy
1
<label id="titleLabel">Enable Live Edit For:</label>
2
<label for="dataGridCheckbox">Data Grid</label>
3
<input type="checkbox" id="dataGridCheckbox" onchange="editDataGrid()">
4
<label for="timelineCheckbox">Timeline</label>
5
<input type="checkbox" id="timelineCheckbox" onchange="editTimeline()">
6
<label for="periodsCheckbox">Periods</label>
7
<input type="checkbox" id="periodsCheckbox" onchange="editPeriods()">
8
<div id="container"></div>
CSScopy
19
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
#titleLabel {
12
font-weight: 600;
13
}
14
#container {
15
position: absolute;
16
width: 100%;
17
top: 40px;
18
bottom: 0;
19
}
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
chart = anychart.ganttResource();
33
34
// set the data
35
chart.data(treeData);
36
37
// configure the scale
38
chart.getTimeline().scale().minimum("2018-01-01");
39
chart.getTimeline().scale().maximum("2018-03-28");
40
41
// disable timeline tooltips
42
chart.getTimeline().tooltip(false);
43
44
// disable labels of timeline elements
45
chart.getTimeline().elements().labels(false);
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
});
56
57
// allow / forbid editing the data grid
58
function editDataGrid() {
59
if (document.getElementById("dataGridCheckbox").checked) {
60
chart.dataGrid().edit(true);
61
} else {
62
chart.dataGrid().edit(false);
63
}
64
}
65
66
// allow / forbid editing the timeline
67
function editTimeline() {
68
if (document.getElementById("timelineCheckbox").checked) {
69
chart.getTimeline().edit(true);
70
chart.getTimeline().periods().edit(true);
71
document.getElementById("periodsCheckbox").checked = true;
72
} else {
73
chart.getTimeline().edit(false);
74
chart.getTimeline().periods().edit(false);
75
document.getElementById("periodsCheckbox").checked = false;
76
77
}
78
}
79
80
// allow / forbid editing periods
81
function editPeriods() {
82
if (document.getElementById("periodsCheckbox").checked) {
83
chart.getTimeline().periods().edit(true);
84
} else {
85
chart.getTimeline().periods().edit(false);
86
}
87
}