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
// create data set on our data
3
var dataSet = anychart.data.set(getData());
4
5
// map data for the first series, take x from the zero column and value from the first column of data set
6
var firstSeriesData = dataSet.mapAs({ x: 0, value: 1 });
7
8
// map data for the second series, take x from the zero column and value from the second column of data set
9
var secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });
10
11
// map data for the third series, take x from the zero column and value from the third column of data set
12
var thirdSeriesData = dataSet.mapAs({ x: 0, value: 3 });
13
14
// create line chart
15
var chart = anychart.line();
16
17
// turn on chart animation
18
chart.animation(true);
19
20
// set chart padding
21
chart.padding([10, 20, 5, 20]);
22
23
// turn on the crosshair
24
chart.crosshair().enabled(true).yLabel(false).yStroke(null);
25
26
// set tooltip mode to point
27
chart.tooltip().positionMode('point');
28
29
// set chart title text settings
30
chart.title(
31
'Trend of Sales of the Most Popular Products of ACME Corp.'
32
);
33
34
// set yAxis title
35
chart.yAxis().title('Number of Bottles Sold (thousands)');
36
chart.xAxis().labels().padding(5);
37
38
// create first series with mapped data
39
var firstSeries = chart.line(firstSeriesData);
40
firstSeries.name('Brandy');
41
firstSeries.hovered().markers().enabled(true).type('circle').size(4);
42
firstSeries
43
.tooltip()
44
.position('right')
45
.anchor('left-center')
46
.offsetX(5)
47
.offsetY(5);
48
49
// create second series with mapped data
50
var secondSeries = chart.line(secondSeriesData);
51
secondSeries.name('Whiskey');
52
secondSeries.hovered().markers().enabled(true).type('circle').size(4);
53
secondSeries
54
.tooltip()
55
.position('right')
56
.anchor('left-center')
57
.offsetX(5)
58
.offsetY(5);
59
60
// create third series with mapped data
61
var thirdSeries = chart.line(thirdSeriesData);
62
thirdSeries.name('Tequila');
63
thirdSeries.hovered().markers().enabled(true).type('circle').size(4);
64
thirdSeries
65
.tooltip()
66
.position('right')
67
.anchor('left-center')
68
.offsetX(5)
69
.offsetY(5);
70
71
// turn the legend on
72
chart.legend().enabled(true).fontSize(13).padding([0, 0, 10, 0]);
73
74
// set container id for the chart
75
chart.container('container');
76
// initiate chart drawing
77
chart.draw();
78
});
79
80
function getData() {
81
return [
82
['1986', 3.6, 2.3, 2.8, 11.5],
83
['1987', 7.1, 4.0, 4.1, 14.1],
84
['1988', 8.5, 6.2, 5.1, 17.5],
85
['1989', 9.2, 11.8, 6.5, 18.9],
86
['1990', 10.1, 13.0, 12.5, 20.8],
87
['1991', 11.6, 13.9, 18.0, 22.9],
88
['1992', 16.4, 18.0, 21.0, 25.2],
89
['1993', 18.0, 23.3, 20.3, 27.0],
90
['1994', 13.2, 24.7, 19.2, 26.5],
91
['1995', 12.0, 18.0, 14.4, 25.3],
92
['1996', 3.2, 15.1, 9.2, 23.4],
93
['1997', 4.1, 11.3, 5.9, 19.5],
94
['1998', 6.3, 14.2, 5.2, 17.8],
95
['1999', 9.4, 13.7, 4.7, 16.2],
96
['2000', 11.5, 9.9, 4.2, 15.4],
97
['2001', 13.5, 12.1, 1.2, 14.0],
98
['2002', 14.8, 13.5, 5.4, 12.5],
99
['2003', 16.6, 15.1, 6.3, 10.8],
100
['2004', 18.1, 17.9, 8.9, 8.9],
101
['2005', 17.0, 18.9, 10.1, 8.0],
102
['2006', 16.6, 20.3, 11.5, 6.2],
103
['2007', 14.1, 20.7, 12.2, 5.1],
104
['2008', 15.7, 21.6, 10, 3.7],
105
['2009', 12.0, 22.5, 8.9, 1.5]
106
];
107
}