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
61
1
anychart.onDocumentReady(function() {
2
3
// data
4
var data = anychart.data.set([
5
["John", 10000, 12000, 20000, 16000],
6
["Jake", 12000, 15000, 19000, 21000],
7
["Peter", 16000, 17000, 21000, 22000]
8
]);
9
10
// map data
11
var Quarter1 = data.mapAs({x: [0], value: [1]});
12
var Quarter2 = data.mapAs({x: [0], value: [2]});
13
var Quarter3 = data.mapAs({x: [0], value: [3]});
14
var Quarter4 = data.mapAs({x: [0], value: [4]});
15
16
// chart type
17
var chart = anychart.bar();
18
19
// set title
20
chart.title("Legend Title Configuration");
21
22
// set data
23
var series1 = chart.bar(Quarter1);
24
series1.name("Quarter 1");
25
var series2 = chart.bar(Quarter2);
26
series2.name("Quarter 2");
27
var series3 = chart.bar(Quarter3);
28
series3.name("Quarter 3");
29
var series4 = chart.bar(Quarter4);
30
series4.name("Quarter 4");
31
32
// legend settings
33
var legend = chart.legend();
34
legend.titleSeparator(true);
35
// enable legend
36
legend.enabled(true);
37
// set legend position
38
legend.position("right");
39
// set legend align
40
legend.align("top");
41
// set items layout
42
legend.itemsLayout("vertical");
43
44
// settings for legend title
45
var legendTitle = chart.legend().title();
46
legendTitle.useHtml(true);
47
// enables legend title
48
legendTitle.enabled(true);
49
legendTitle.text("Total sales<br><i style=\"color: #999; font-weight: 400; font-size: 11px;\">(Year 2004)</i>");
50
// set font size
51
legendTitle.fontSize(14);
52
legendTitle.hAlign("center");
53
54
var xAxis = chart.xAxis();
55
xAxis.title("Sales");
56
var yAxis = chart.yAxis();
57
yAxis.title("Manager");
58
// draw chart
59
chart.container("container");
60
chart.draw();
61
});