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
// data
4
var data = [
5
{x: "Chocolate paste", value: 5},
6
{x: "White honey", value: 2},
7
{x: "Strawberry jam", value: 2},
8
{x: "Condensed milk", value: 1}
9
];
10
11
// set chart type
12
var chart = anychart.pie(data);
13
14
// set chart title
15
chart.title("The kind of pancakes preferred at the Sochi 2014 Olympic Games");
16
17
// set chart container
18
chart.container("container");
19
20
// set chart bounds
21
chart.bounds(0, 0, chart.container().width()-35, chart.container().height());
22
23
// initiate chart drawing
24
chart.draw();
25
26
// create new buttons
27
var printButton = document.createElement("div");
28
29
printButton.className = "custombutton";
30
31
printButton.innerHTML = "Save as PDF";
32
33
printButton.onclick = function() {
34
chart.saveAsPdf();
35
};
36
37
// append button to container
38
container.appendChild(printButton);
39
40
var custombuttons = document.getElementsByClassName("custombutton");
41
42
for (var i = 0; i<custombuttons.length; i++){
43
// set button style
44
custombuttons[i].style.top = 65*i + "px";
45
custombuttons[i].style.right = "5px";
46
custombuttons[i].style.width = "80px";
47
custombuttons[i].style.height = "auto";
48
custombuttons[i].style.backgroundColor = "#444444";
49
custombuttons[i].style.color = "white";
50
custombuttons[i].style.fontFamily = chart.title().fontFamily();
51
custombuttons[i].style.position = "absolute";
52
custombuttons[i].style.zIndex = 2;
53
custombuttons[i].style.transition = "0.5s";
54
custombuttons[i].style.textAlign = "center";
55
custombuttons[i].style.border = "3px solid #444444";
56
custombuttons[i].style.borderRadius = "7px 7px 7px 7px";
57
custombuttons[i].style.fontSize = "15px";
58
custombuttons[i].style.cursor = "pointer";
59
}
60
});