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
{id: "A", duration: 1, name: "A"},
6
{id: "B", duration: 3, name: "B"},
7
{id: "C", duration: 2, name: "C"},
8
{id: "D", duration: 1, name: "D", dependsOn: ["A"]},
9
{id: "E", duration: 2, name: "E", dependsOn: ["B"]},
10
{id: "F", duration: 2, name: "F", dependsOn: ["C"]},
11
{id: "G", duration: 2, name: "G", dependsOn: ["D", "E", "F"]}
12
];
13
14
// create a chart
15
var chart = anychart.pert();
16
17
// set chart data
18
chart.data(data, "as-table");
19
20
chart.milestones().labels().fontSize(10);
21
chart.milestones().shape("rectangle");
22
chart.milestones().size(80);
23
24
chart.milestones().labels().format(function() {
25
if (this.creator) {
26
var result ="";
27
var comma, i;
28
29
for (i = 0; i < this.predecessors.length; i++){
30
comma = i == this.predecessors.length - 1 ? "" : ",";
31
result += this.predecessors[i].get("name") + comma;
32
}
33
result += " - ";
34
35
for (i = 0; i < this.successors.length; i++){
36
comma = i == this.successors.length - 1 ? "" : ",";
37
result += this.successors[i].get("name") + comma;
38
}
39
return result;
40
41
} else {
42
return this.isStart ? "S" : "F";
43
}
44
});
45
46
chart.criticalPath({milestones: {fill: "#ffcc80", hoverFill: "#ffab91", selectFill: "#ff6e40"}});
47
48
// set the title of the chart
49
chart.title("PERT Chart");
50
51
// set the container id for the chart
52
chart.container("container");
53
54
// initiate drawing the chart
55
chart.draw();
56
});