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 html for the legend
35
chart.legend().useHtml(true);
36
37
// configure the format of legend items
38
chart.legend().itemsFormat(function() {
39
return "<span style='color:" + this.series.color() +
40
";font-weight:600'>" + this.series.name() +
41
"</span>: $" + this.series.getStat("sum");
42
});
43
44
// set the chart title
45
chart.title("Legend Items: Text Format (Formatting Functions)" +
46
"\nMultiple Series");
47
48
// set the container id
49
chart.container("container");
50
51
// initiate drawing the chart
52
chart.draw();
53
});