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
66
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
// create main timeline data points
10
for (var i = 0; i < data.pfizerTimeline.length; i++) {
11
// create a range series
12
var series = chart.range([
13
[
14
data.pfizerTimeline[i].title,
15
data.pfizerTimeline[i].start,
16
data.pfizerTimeline[i].end
17
]
18
]);
19
}
20
21
// create a data set for the top data points
22
var pfizerDataSet = anychart.data.set(data.pfizerFacts);
23
24
// map the top data points
25
var pfizerMapping = pfizerDataSet.mapAs({
26
x: 'date',
27
value: 'title'
28
});
29
30
// create the top series with moments
31
var pfizerMappingSeries = chart.moment(pfizerMapping);
32
33
// create a data set for the bottom data points
34
var otherVaccinesDataset = anychart.data.set(data.otherVaccines);
35
36
// map the bottom data set
37
var otherVaccinesDatasetMapping = otherVaccinesDataset.mapAs({
38
x: 'date',
39
value: 'title'
40
});
41
42
// create the bottom series with moments
43
var otherVaccinesSeries = chart.moment(otherVaccinesDatasetMapping);
44
45
// set the chart scale levels
46
chart.scale().zoomLevels([
47
[
48
{ unit: 'month', count: 1 }
49
]
50
]);
51
52
// enable the chart scroller
53
chart.scroller().enabled(true);
54
55
// set the chart's title
56
chart.title('Pfizer/BioNTech Vaccine Timeline');
57
58
// set the container id for the chart
59
chart.container('container');
60
61
// initiate the chart drawing
62
chart.draw();
63
64
}
65
);
66
});