HTMLcopy
1
<button onclick="png()">PNG</button>
2
<button onclick="svg()">SVG</button>
3
<button onclick="jpg()">JPG</button>
4
<div id="container"></div>
CSScopy
15
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
button {
8
margin: 10px 0 0 10px;
9
}
10
#container {
11
position: absolute;
12
width: 100%;
13
top: 35px;
14
bottom: 0;
15
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// data
4
var data = [
5
["Chocolate paste", 5],
6
["White honey", 2],
7
["Strawberry jam", 2],
8
["Condensed milk", 1]
9
];
10
11
// set chart type
12
chart = anychart.bar(data);
13
14
// set chart title
15
chart.title("Save as Image Buttons");
16
17
// display chart
18
chart.container("container").draw();
19
});
20
21
// save the chart as png
22
function png() {
23
chart.saveAsPng({"width": 360,
24
"height": 500,
25
"quality": 0.3,
26
"filename": "My Chart PNG"});
27
};
28
29
// save the chart as svg
30
function svg() {
31
chart.saveAsSvg({"paperSize": "A4",
32
"landscape": false,
33
"filename": "My Chart SVG"});
34
};
35
36
// save the chart as jpg
37
function jpg() {
38
chart.saveAsJpg({"width": 360,
39
"height": 500,
40
"quality": 0.3,
41
"forceTransparentWhite": false,
42
"filename": "My Chart JPG"});
43
};