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.column();
20
21
// create series, set the data and names
22
var series1 = chart.column(seriesData1);
23
var series2 = chart.column(seriesData2);
24
var series3 = chart.column(seriesData3);
25
var series4 = chart.column(seriesData4);
26
series1.name("2015");
27
series2.name("2016");
28
series3.name("2017");
29
series4.name("2018");
30
31
// enable the legend
32
var legend = chart.legend();
33
legend.enabled(true);
34
35
/* prevent the cursor from changing
36
when it hovers over the legend */
37
legend.hoverCursor("default");
38
39
/* listen to the legendItemMouseDown event
40
and prevent the default behavior of the legend
41
and the legendItemClick event */
42
legend.listen("legendItemMouseDown", function(e) {
43
e.preventDefault();
44
e.stopPropagation();
45
});
46
47
/* listen to the legendItemMouseOver event
48
and prevent the default behavior of the legend */
49
legend.listen("legendItemMouseOver", function(e) {
50
e.preventDefault();
51
});
52
53
/* prevent points from being deselected
54
when a click happens outside of them */
55
chart.interactivity().unselectOnClickOutOfPoint(false);
56
57
/* listen to the pointsSelect event
58
and configure the appearance of the legend item */
59
chart.listen("pointsSelect", function(e) {
60
e.currentPoint.series.legendItem().iconFill("#455a64");
61
for (var i = 0; i < chart.getSeriesCount(); i++) {
62
var series = chart.getSeriesAt(i);
63
if (series.meta("selected") & series != e.currentPoint.series) {
64
series.meta("selected", false);
65
series.legendItem().iconFill(series.color());
66
}
67
}
68
e.currentPoint.series.meta("selected", true);
69
});
70
71
/* listen to the pointMouseOver event
72
and configure the appearance of the legend item */
73
chart.listen("pointMouseOver", function(e) {
74
if (!e.series.meta("selected")) {
75
color = anychart.color.lighten(e.series.color());
76
e.series.legendItem().iconFill(color);
77
}
78
});
79
80
/* listen to the pointMouseOut event
81
and reset appearance of the legend item */
82
chart.listen("pointMouseOut", function(e) {
83
if (!e.series.meta("selected")) {
84
e.series.legendItem().iconFill(e.series.color());
85
}
86
});
87
88
// set the chart title
89
chart.title().useHtml(true);
90
chart.title("Events: Chart Points (Multiple Series)<br><br>" +
91
"<span style='font-size:12; font-style:italic'>" +
92
"Click on and Hover over Chart Points");
93
94
// set the container id
95
chart.container("container");
96
97
// initiate drawing the chart
98
chart.draw();
99
});