1.先导入exporting.js
2.添加功能
exporting: {
buttons: {
contextButton: {
x: 10,
y: 10
}
}
},
3.上面的添加好之后就可以实现下载图片功能.但是功能描述是英文.所以可以使用下面的lang修改
lang 属于全局配置,对当前页面的所有图表有效,对应的汉化后的配置是:
lang: {
viewFullscreen: "全屏",
contextButtonTitle: "图表导出菜单",
printChart:"打印图表",
decimalPoint: ".",
downloadJPEG: "下载JPEG图片",
downloadPDF: "下载PDF文件",
downloadPNG: "下载PNG文件",
downloadSVG: "下载SVG文件"
},
4.导出的图片名称为chart .所以可以修改名称
exporting: {
buttons: {
contextButton: {
x: 10,
y: 10
}
},
filename:'时间段统计图'
},
5.也可通过button 按钮控制.
html
<div id="container"></div>
<button id="button">导出图表</button>
js
$(function () {
var chart = Highcharts.chart('container', {
title: {
text: '外部调用导出'
},
credits: {
enabled: false
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
exporting: {
enabled: false, // 关闭导出按钮
url: 'https://export.highcharts.com.cn'
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}],
navigation: {
buttonOptions: { // 关闭导出按钮,效果同上
enabled: false
}
}
});
// the button handler
$('#button').click(function () {
chart.exportChart({
type: 'application/pdf',
filename: 'my-pdf'
});
});
});