HTMLcopy
1
<label>Column 2:</label>
2
<label><input onclick="switchPreset('date-common-log')" type="radio" name="preset" checked>date-common-log</label>
3
<label><input onclick="switchPreset('date-dmy-dots')" type="radio" name="preset">date-dmy-dots</label>
4
<label><input onclick="switchPreset('date-iso-8601')" type="radio" name="preset">date-iso-8601</label>
5
<label><input onclick="switchPreset('date-us-short')" type="radio" name="preset">date-us-short</label>
6
<div id="container"></div>
CSScopy
16
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
#container {
12
position: absolute;
13
width: 100%;
14
top: 40px;
15
bottom: 0;
16
}
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("actualStart", "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("actualStart", "date-common-log");
62
column_2.title("date-common-log");
63
column_2.title().fontSize(10);
64
column_2.title().wordWrap("break-word");
65
column_2.title().padding(7);
66
column_2.depthPaddingMultiplier(0);
67
column_2.collapseExpandButtons(false);
68
69
// set the position of the splitter
70
chart.splitterPosition("40%");
71
72
// configure the scale
73
chart.getTimeline().scale().maximum("2018-03-15");
74
75
// set the container id
76
chart.container("container");
77
78
// initiate drawing the chart
79
chart.draw();
80
81
// fit elements to the width of the timeline
82
chart.fitAll();
83
});
84
85
// switch the preset of the second data grid column
86
function switchPreset(preset) {
87
column_2.setColumnFormat("actualStart", preset);
88
// update the column title
89
if (preset == "date-common-log") {
90
column_2.title("date-common-log");
91
}
92
if (preset == "date-dmy-dots") {
93
column_2.title("date-dmy-dots");
94
}
95
if (preset == "date-iso-8601") {
96
column_2.title("date-iso-8601");
97
}
98
if (preset == "date-us-short") {
99
column_2.title("date-us-short");
100
}
101
}