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
210
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
11
.title()
12
.enabled(true)
13
.useHtml(true)
14
.text(
15
'<span style = "color: #007cc2; font-size:20px;">Pfizer/BioNTech Vaccine Timeline</span>' +
16
'<br/><span style="font-size: 16px;">(Comparing with other vaccines approved in USA)</span>'
17
);
18
19
20
// create the main timeline data points
21
for (var i = 0; i < data.pfizerTimeline.length; i++) {
22
// create a range series
23
var series = chart.range([
24
[
25
data.pfizerTimeline[i].title,
26
data.pfizerTimeline[i].start,
27
data.pfizerTimeline[i].end
28
]
29
])
30
.fill(function(d){
31
if(d.name == "Pfizer/BioNTech Trial"){
32
return "#FD8060"
33
}else if(d.name == "Review"){
34
return "#FEE191"
35
}
36
return "#B0D8A4"
37
})
38
.stroke("none");
39
40
// set the tooltip settings for the main timeline series
41
series
42
.tooltip()
43
.useHtml(true)
44
.titleFormat('{%x}')
45
.format(
46
data.pfizerTimeline[i].description
47
+ '<br/><br/>Start: <b>{%start}{type:date}</b><br/>End: <b>{%end}{type:date}</b>'
48
);
49
50
}
51
52
// create a data set for the top data points
53
var pfizerDataSet = anychart.data.set(data.pfizerFacts);
54
55
// map the top data points
56
var pfizerMapping = pfizerDataSet.mapAs({
57
x: 'date',
58
value: 'title'
59
});
60
61
// create the top series with moments
62
var pfizerMappingSeries = chart.moment(pfizerMapping);
63
pfizerMappingSeries.normal().markers().fill("#007cc2");
64
65
// set the tooltip settings for the main timeline series
66
pfizerMappingSeries
67
.tooltip()
68
.useHtml(true)
69
.titleFormat('{%title}')
70
.format(
71
'{%description}'
72
+ '<br/><br/>Date: <b>{%date}{type:date}</b><br/>'
73
);
74
75
var modernaData = [],
76
johnsonData =[],
77
novavaxData =[];
78
79
for (var i = 0; i < data.otherVaccines.length; i++) {
80
if(data.otherVaccines[i].title.startsWith("Moderna")){
81
modernaData.push(data.otherVaccines[i]);
82
}else if(data.otherVaccines[i].title.startsWith("Johnson")){
83
johnsonData.push(data.otherVaccines[i]);
84
}else{
85
novavaxData.push(data.otherVaccines[i]);
86
}
87
}
88
89
// create a data set for the bottom data points - Moderna
90
var modernaDataset = anychart.data.set(modernaData);
91
92
// map the bottom data set - Moderna
93
var modernaDatasetMapping = modernaDataset.mapAs({
94
x: 'date',
95
value: 'title'
96
});
97
98
// create the bottom series - Moderna
99
var modernaSeries = chart.moment(modernaDatasetMapping);
100
101
// set the direction for the series
102
modernaSeries.direction("down");
103
104
// set the tooltip settings for the Moderna series
105
modernaSeries
106
.tooltip()
107
.useHtml(true)
108
.titleFormat('{%title}')
109
.format(
110
'{%description}'
111
+ '<br/><br/>Date: <b>{%date}{type:date}</b><br/>'
112
);
113
114
// create a data set for the bottom data points - Johnson
115
var johnsonDataset = anychart.data.set(johnsonData);
116
117
// map the bottom data set - Johnson
118
var johnsonDatasetMapping =johnsonDataset.mapAs({
119
x: 'date',
120
value: 'title'
121
});
122
123
// create the bottom series - Johnson
124
var johnsonSeries = chart.moment(johnsonDatasetMapping);
125
126
// set the direction for the series
127
johnsonSeries.direction("down");
128
129
// set the tooltip settings for the Johnson series
130
johnsonSeries
131
.tooltip()
132
.useHtml(true)
133
.titleFormat('{%title}')
134
.format(
135
'{%description}'
136
+ '<br/><br/>Date: <b>{%date}{type:date}</b><br/>'
137
);
138
139
// create a data set for the bottom data points - Novavax
140
var novavaxDataset = anychart.data.set(novavaxData);
141
142
// map the bottom data set - Novavax
143
var novavaxDatasetMapping = novavaxDataset.mapAs({
144
x: 'date',
145
value: 'title'
146
});
147
148
// create the bottom series - Novavax
149
var novavaxSeries = chart.moment(novavaxDatasetMapping);
150
151
// set the direction for the series
152
novavaxSeries.direction("down");
153
154
// set the tooltip settings for the Novavax series
155
novavaxSeries
156
.tooltip()
157
.useHtml(true)
158
.titleFormat('{%title}')
159
.format(
160
'{%description}'
161
+ '<br/><br/>Date: <b>{%date}{type:date}</b><br/>'
162
);
163
164
// set the chart scale levels
165
chart.scale().zoomLevels([
166
[
167
{ unit: 'month', count: 1 }
168
]
169
]);
170
171
// enable the chart scroller
172
chart.scroller().enabled(true);
173
174
// create two text markers
175
var textMarker1 = chart.textMarker(0);
176
var textMarker2 = chart.textMarker(1);
177
178
// set the values of the markers
179
textMarker1.value(data.pfizerTimeline[0].start);
180
textMarker2.value(data.pfizerTimeline[0].start);
181
182
// set the text of the markers
183
textMarker1.useHtml(true);
184
textMarker1.text(
185
"Facts about Pfizer");
186
textMarker2.text(
187
"Facts about other vaccines in USA");
188
189
// configure the position of the markers
190
textMarker1.anchor("leftcenter");
191
textMarker2.anchor("leftcenter");
192
textMarker1.rotation(0);
193
textMarker2.rotation(0);
194
textMarker1.offsetY('35%');
195
textMarker2.offsetY('60%');
196
197
// configure the font of the markers
198
textMarker1.fontColor("#007cc2");
199
textMarker1.fontWeight(600);
200
textMarker2.fontWeight(600);
201
202
// set the container id for the chart
203
chart.container('container');
204
205
// initiate the chart drawing
206
chart.draw();
207
208
}
209
);
210
});