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
// Converting full date to a
2
Date.prototype.secondsInCurrentHour=function(){
3
let date = new Date(this); // create a new Date object with the given timestamp
4
let minutes = date.getMinutes(); // get the number of minutes in the current hour
5
let seconds = date.getSeconds(); // get the number of seconds in the current minute
6
let secondsInHour = minutes * 60 + seconds; // calculate the total number of seconds in the current hour
7
return secondsInHour
8
};
9
10
anychart.onDocumentReady(function() {
11
var data = [
12
{
13
id: "1",
14
name: "Robot Line",
15
actualStart: "2023-02-21T01:00:54",
16
actualEnd: "2023-02-21T01:01:14",
17
children: [
18
{
19
id: "1_1",
20
name: "Assembly",
21
actualStart: "2023-02-21T01:00:57",
22
actualEnd: "2023-02-21T01:01:01"
23
},
24
{
25
id: "1_2",
26
name: "Welding",
27
actualStart: "2023-02-21T01:01:01",
28
actualEnd: "2023-02-21T01:01:06"
29
},
30
{
31
id: "1_3",
32
name: "Painting",
33
actualStart: "2023-02-21T01:01:06",
34
actualEnd: "2023-02-21T01:01:14"
35
}
36
]
37
}
38
];
39
// create a data tree
40
var treeData = anychart.data.tree(data, "as-tree", null, {
41
children: "children"
42
});
43
// map the data
44
var mapping = treeData.mapAs({
45
actualStart: "actualStart",
46
actualEnd: "actualEnd",
47
name: "name"
48
});
49
// create a data tree
50
// var mapping = anychart.data.tree(data, "as-tree");
51
anychart.format.outputDateTimeFormat("d MMMM");
52
// create a chartec
53
54
var chart = anychart.ganttProject();
55
56
// set the data
57
chart.data(mapping);
58
59
// set the container id
60
chart.container("container");
61
// set the data
62
chart.dataGrid().fixedColumns(true);
63
// chart.splitterPosition().hide();
64
chart.dataGrid().column().enabled(false);
65
chart.dataGrid().column(0).enabled(false);
66
chart.getTimeline().elements().labels(false);
67
chart.rowHoverFill("#ffd54f 0.3");
68
chart.rowSelectedFill("#ffd54f 0.3");
69
chart.rowStroke("0.5 #64b5f6");
70
chart.columnStroke("0.5 #64b5f6");
71
72
chart.dataGrid().column(0).enabled(false);
73
74
var title = chart.title();
75
title.enabled(true);
76
title.text("Gantt Chart");
77
title.fontColor("#64b5f6");
78
title.fontSize(18);
79
title.fontWeight(600);
80
title.padding(5);
81
82
scale = chart.xScale();
83
84
// Set zoom levels.
85
scale.zoomLevels([
86
[{
87
unit: 'millisecond',
88
count: 0
89
},
90
{
91
unit: 'second',
92
count: 1
93
}
94
]
95
]);
96
97
// configure the levels of the timeline header
98
var header = chart.getTimeline().header();
99
// this function format apperance of a seconds in a timeline header
100
header.level(0).format((e)=>{
101
let tickDate = new Date(e.tickValue)
102
let currentSecond = tickDate.secondsInCurrentHour(e.tickValue)
103
return currentSecond
104
});
105
header.level(1).enabled(false);
106
header.level(2).enabled(false);
107
chart.headerHeight(50);
108
// initiate drawing the chart
109
chart.draw();
110
// fit elements to the width of the timeline
111
chart.fitAll();
112
113
});