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