HTMLcopy
1
<script src="https://cdn.anychart.com/releases/8.10.0/js/anychart-base.min.js"></script>
2
<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 data set on our data
4
var dataSet = anychart.data.set(getData());
5
6
// map data for the line chart,
7
// take x from the zero column and value from the first column
8
var seriesData = dataSet.mapAs({ x: 0, value: 1 });
9
10
// create a line chart
11
var chart = anychart.line();
12
13
// configure the chart title text settings
14
chart.title('Acceptance of same-sex relationships in the US over the last 2 decades');
15
16
// set the y axis title
17
chart.yAxis().title('% of people who accept same-sex relationships');
18
19
// create a line series with the mapped data
20
var lineChart = chart.line(seriesData);
21
22
// set the container id for the line chart
23
chart.container('container');
24
25
// draw the line chart
26
chart.draw();
27
28
});
29
30
function getData() {
31
return [
32
['1990',12],
33
['1991',14],
34
['1993',21],
35
['1994',21],
36
['1996',26],
37
['1998',26],
38
['2000',27],
39
['2002',31],
40
['2004',29],
41
['2006',31],
42
['2008',36],
43
['2010',41],
44
['2012',42],
45
['2014',48],
46
['2016',50],
47
['2018',57]
48
];
49
}