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.loadCsvFile(
3
'https://static.anychart.com/git-storage/word-press/data/covid-19-italy/data.csv',
4
function (data) {
5
// set the data and ignore the first row that contains headers
6
var dataSet = anychart.data.set(data, {ignoreFirstRow: true});
7
8
// map data for the deaths series
9
var deathsData = dataSet.mapAs({ 'x': 0, 'value': 2 });
10
11
// map data for the recovered series
12
var recoveredData = dataSet.mapAs({ 'x': 0, 'value': 3 });
13
14
// map data for the active series
15
var activeData = dataSet.mapAs({ 'x': 0, 'value': 4 });
16
17
// specify the chart type
18
var chart = anychart.area();
19
20
// helper function to setup series and give them appropriate names in order to distinguish and label them properly
21
var setupSeries = function (series, name) {
22
series.name(name);
23
// setting the markers
24
series.hovered().stroke('3 #fff 1');
25
series.hovered().markers()
26
.enabled(true)
27
.type('circle')
28
.size(4)
29
.stroke('1.5 #fff');
30
series.markers().zIndex(100);
31
};
32
33
// create a series with the mapped active data
34
var actSeries = chart.splineArea(activeData)
35
.fill('#1E8FCD')
36
.stroke('#4b9bc6');
37
setupSeries(actSeries, 'Active');
38
39
// create a series with the mapped recovered data
40
var recSeries = chart.splineArea(recoveredData)
41
.fill('#B3C67D')
42
.stroke('#b9c1a0');
43
setupSeries(recSeries, 'Recovered');
44
45
// create a series with the mapped deaths data
46
var deathsSeries = chart.splineArea(deathsData)
47
.fill('#b3315d')
48
.stroke('#b5617d');
49
setupSeries(deathsSeries, 'Deaths');
50
51
// force the chart to stack values by the y scale
52
chart.yScale().stackMode('percent');
53
54
// set the chart title
55
chart.title('Covid-19 in Italy');
56
57
// set the labels of the axes
58
chart.xAxis().title('Date');
59
chart.yAxis().title('Number of people');
60
61
// turn on the crosshair
62
var crosshair = chart.crosshair();
63
crosshair.enabled(true)
64
.yStroke(null)
65
.xStroke('#fff')
66
.zIndex(39);
67
crosshair.yLabel().enabled(false);
68
69
// turn on the legend
70
chart.legend(true);
71
72
// turn on the chart animation
73
chart.animation(true);
74
75
// set the container id for the chart
76
chart.container('container');
77
78
// initiate chart drawing
79
chart.draw();
80
});
81
});