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.bar();
13
14
// set data
15
var series = chart.bar(data);
16
17
// set chart title
18
chart.title("The kind of pancakes preferred at the Sochi 2014 Olympic Games");
19
20
// set chart container
21
chart.container("container");
22
23
// set chart bounds
24
chart.bounds(0, 0, chart.container().width()-35, chart.container().height());
25
26
// initiate chart drawing
27
chart.draw();
28
29
// create new buttons
30
var svgButton = document.createElement("div");
31
var pngButton = document.createElement("div");
32
var jpgButton = document.createElement("div");
33
34
svgButton.className = "custombutton";
35
pngButton.className = "custombutton";
36
jpgButton.className = "custombutton";
37
38
svgButton.innerHTML = "SVG";
39
pngButton.innerHTML = "PNG";
40
jpgButton.innerHTML = "JPG";
41
42
pngButton.onclick = function() {
43
chart.saveAsPng();
44
};
45
svgButton.onclick = function() {
46
chart.saveAsSvg();
47
};
48
jpgButton.onclick = function() {
49
chart.saveAsJpg();
50
};
51
52
// append button to container
53
container.appendChild(svgButton);
54
container.appendChild(pngButton);
55
container.appendChild(jpgButton);
56
57
var custombuttons = document.getElementsByClassName("custombutton");
58
59
// set style for all buttons
60
for (var i = 0; i<custombuttons.length; i++){
61
// set button style
62
custombuttons[i].style.top = 45*i + "px";
63
custombuttons[i].style.right = "5px";
64
custombuttons[i].style.width = "40px";
65
custombuttons[i].style.height = "auto";
66
custombuttons[i].style.backgroundColor = "#444444";
67
custombuttons[i].style.color = "white";
68
custombuttons[i].style.fontFamily = chart.title().fontFamily();
69
custombuttons[i].style.position = "absolute";
70
custombuttons[i].style.zIndex = 2;
71
custombuttons[i].style.transition = "0.5s";
72
custombuttons[i].style.textAlign = "center";
73
custombuttons[i].style.border = "3px solid #444444";
74
custombuttons[i].style.borderRadius = "7px 7px 7px 7px";
75
custombuttons[i].style.fontSize = "18px";
76
custombuttons[i].style.cursor = "pointer";
77
}
78
});