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 data
4
var data = [
5
{x: "John", value: 5000},
6
{x: "Richard", value: 5000},
7
{x: "Larry", value: 5000},
8
{x: "Marta", value: 15000}
9
];
10
11
// create a chart and set the data
12
chart = anychart.pie(data);
13
14
/* prevent the cursor from changing
15
when it hovers over the legend */
16
chart.legend().hoverCursor("default");
17
18
/* listen to the legendItemMouseDown event
19
and prevent the default behavior of the legend
20
and the legendItemClick event */
21
chart.legend().listen("legendItemMouseDown", function(e) {
22
e.preventDefault();
23
e.stopPropagation();
24
});
25
26
/* listen to the legendItemMouseOver event
27
and prevent the default behavior of the legend */
28
chart.legend().listen("legendItemMouseOver", function(e) {
29
e.preventDefault();
30
});
31
32
/* listen to the pointClick event
33
and configure the appearance of the legend item */
34
chart.listen("pointClick", function(e) {
35
if (e.point.selected()) {
36
e.point.set("legendItem", {iconFill: "#455a64"});
37
} else {
38
e.point.set("legendItem", null);
39
}
40
});
41
42
// set the chart title
43
chart.title().useHtml(true);
44
chart.title("Events: Chart Points (Single Series)<br><br>" +
45
"<span style='font-size:12; font-style:italic'>" +
46
"Click on Chart Points");
47
48
// set the container id
49
chart.container("container");
50
51
// initiate drawing the chart
52
chart.draw();
53
});