HTMLcopy
x
1
<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-core.min.js"></script>
2
<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-timeline.min.js"></script>
3
<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-data-adapter.min.js"></script>
4
5
<div id="container"></div>
CSScopy
8
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
JavaScriptcopy
125
1
anychart.onDocumentReady(function () {
2
anychart.data.loadJsonFile(
3
'https://gist.githubusercontent.com/shacheeswadia/c65106bb00db4236140b4f6052fde55a/raw/9ec2af927a8bb81433f2236b41c161260aa4950d/pfizer-comparison-timeline',
4
function (data) {
5
6
// create a timeline chart
7
var chart = anychart.timeline();
8
9
// set the chart's title
10
chart.title('Pfizer/BioNTech Vaccine Timeline');
11
12
// create main timeline data points
13
for (var i = 0; i < data.pfizerTimeline.length; i++) {
14
// create a range series
15
var series = chart.range([
16
[
17
data.pfizerTimeline[i].title,
18
data.pfizerTimeline[i].start,
19
data.pfizerTimeline[i].end
20
]
21
])
22
.fill(function(d){
23
if(d.name == "Pfizer/BioNTech Trial"){
24
return "#FD8060"
25
}else if(d.name == "Review"){
26
return "#FEE191"
27
}
28
return "#B0D8A4"
29
})
30
.stroke("none");
31
}
32
33
// create a data set for the top data points
34
var pfizerDataSet = anychart.data.set(data.pfizerFacts);
35
36
// map the top data points
37
var pfizerMapping = pfizerDataSet.mapAs({
38
x: 'date',
39
value: 'title'
40
});
41
42
// create the top series with moments
43
var pfizerMappingSeries = chart.moment(pfizerMapping);
44
45
// customize the markers
46
pfizerMappingSeries.normal().markers().fill("#007cc2");
47
48
var modernaData = [],
49
johnsonData =[],
50
novavaxData =[];
51
52
for (var i = 0; i < data.otherVaccines.length; i++) {
53
if(data.otherVaccines[i].title.startsWith("Moderna")){
54
modernaData.push(data.otherVaccines[i]);
55
}else if(data.otherVaccines[i].title.startsWith("Johnson")){
56
johnsonData.push(data.otherVaccines[i]);
57
}else{
58
novavaxData.push(data.otherVaccines[i]);
59
}
60
}
61
62
// create a data set for the bottom data points - Moderna
63
var modernaDataset = anychart.data.set(modernaData);
64
65
// map the bottom data set - Moderna
66
var modernaDatasetMapping = modernaDataset.mapAs({
67
x: 'date',
68
value: 'title'
69
});
70
71
// create the bottom series - Moderna
72
var modernaSeries = chart.moment(modernaDatasetMapping);
73
74
// set the direction for the series
75
modernaSeries.direction("down");
76
77
// create a data set for the bottom data points - Johnson
78
var johnsonDataset = anychart.data.set(johnsonData);
79
80
// map the bottom data set - Johnson
81
var johnsonDatasetMapping =johnsonDataset.mapAs({
82
x: 'date',
83
value: 'title'
84
});
85
86
// create the bottom series - Johnson
87
var johnsonSeries = chart.moment(johnsonDatasetMapping);
88
89
// set the direction for the series
90
johnsonSeries.direction("down");
91
92
// create a data set for the bottom data points - Novavax
93
var novavaxDataset = anychart.data.set(novavaxData);
94
95
// map the bottom data set - Novavax
96
var novavaxDatasetMapping = novavaxDataset.mapAs({
97
x: 'date',
98
value: 'title'
99
});
100
101
// create the bottom series - Novavax
102
var novavaxSeries = chart.moment(novavaxDatasetMapping);
103
104
// set the direction for the series
105
novavaxSeries.direction("down");
106
107
// set the chart scale levels
108
chart.scale().zoomLevels([
109
[
110
{ unit: 'month', count: 1 }
111
]
112
]);
113
114
// enable the chart scroller
115
chart.scroller().enabled(true);
116
117
// set the container id for the chart
118
chart.container('container');
119
120
// initiate the chart drawing
121
chart.draw();
122
123
}
124
);
125
});