HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// create a data set
4
var data = anychart.data.set([
5
["January", 12000, 10000, 7000, 11000],
6
["February", 15000, 12000, 9000, 13000],
7
["March", 16000, 15000, 14000, 12000],
8
["April", 15000, 11000, 13000, 10000],
9
["May", 10000, 9000, 11000, 6000]
10
]);
11
12
// map the data
13
var seriesData1 = data.mapAs({x: 0, value: 1});
14
var seriesData2 = data.mapAs({x: 0, value: 2});
15
var seriesData3 = data.mapAs({x: 0, value: 3});
16
var seriesData4 = data.mapAs({x: 0, value: 4});
17
18
// create a chart
19
var chart = anychart.line();
20
21
// create series, set the data and names
22
var series1 = chart.line(seriesData1);
23
var series2 = chart.line(seriesData2);
24
var series3 = chart.line(seriesData3);
25
var series4 = chart.line(seriesData4);
26
series1.name("2015");
27
series2.name("2016");
28
series3.name("2017");
29
series4.name("2018");
30
31
// enable the legend
32
chart.legend(true);
33
34
// enable and configure the legend tooltip
35
36
var legendTooltip = chart.legend().tooltip();
37
38
legendTooltip.enabled(true);
39
legendTooltip.title(true);
40
legendTooltip.separator(true);
41
42
legendTooltip.titleFormat("Sales Info");
43
legendTooltip.format("Year: {%value}");
44
45
// set the chart title
46
chart.title("Legend: Tooltip (Tokens)");
47
48
// set the container id
49
chart.container("container");
50
51
// initiate drawing the chart
52
chart.draw();
53
});