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
3
// create a line chart
4
var chart = anychart.line();
5
6
// add a chart title
7
chart.title('Perceived threat of COVID-19 by political affiliation (March–August 2020)');
8
9
// create a dataset (democrats)
10
var data1 = anychart.data
11
.set([
12
['Mar', 4.26, 0.1, 0.1],
13
['Apr', 4.46, 0.11, 0.11],
14
['May', 4.36, 0.126, 0.126],
15
['June', 4.29, 0.132, 0.132],
16
['July', 4.49, 0.124, 0.124],
17
['Aug', 4.47, 0.124, 0.124]
18
])
19
.mapAs({
20
x: 0,
21
value: 1,
22
valueLowerError: 2,
23
valueUpperError: 3
24
});
25
26
// create a dataset (republicans)
27
var data2 = anychart.data
28
.set([
29
['Mar', 3.9, 0.144, 0.144],
30
['Apr', 4.09, 0.172, 0.172],
31
['May', 3.71, 0.196, 0.196],
32
['June', 3.54, 0.198, 0.198],
33
['July', 3.78, 0.196, 0.196],
34
['Aug', 3.7, 0.194, 0.195]
35
])
36
.mapAs({
37
x: 0,
38
value: 1,
39
valueLowerError: 2,
40
valueUpperError: 3
41
});
42
43
// set the y-axis parameters
44
var yScale = chart.yScale();
45
yScale.minimum(3.2);
46
yScale.maximum(4.8);
47
48
// create a line series for the first dataset
49
var series1 = chart.line(data1);
50
51
// create a line series for the second dataset
52
var series2 = chart.line(data2);
53
54
// set a container id for the chart
55
chart.container('container');
56
57
// command to draw the chart
58
chart.draw();
59
60
});