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 last legend item
35
series4.legendItem().useHtml(true);
36
37
// configure the format of the last legend item
38
series4.legendItem().format(
39
"{%seriesName}: <span style='color:" + series4.color() +
40
";font-weight:600'>${%seriesYSum}</span>"
41
);
42
43
// set the chart title
44
chart.title("Individual Legend Items: Text Format (Tokens)");
45
46
// set the container id
47
chart.container("container");
48
49
// initiate drawing the chart
50
chart.draw();
51
});