当需要把当前图表导出成excel或者图片时,首先在图表下面添加两个按钮:
<div align="center">
<button id="report_export0">导出Excel</button>
<button id="report_image0">导出图片</button>
</div>
然后在js文件中,添加这两个按钮的响应事件。
$("#report_export" + i).unbind("click");
$("#report_export" + i).bind("click",
{
arg1: provinceID,
arg2: fromDate,
arg3: toDate,
arg4: type,
arg5: year,
arg6: month
},function(event){
var data = event.data;
exportReport(
data.arg1,data.arg2,data.arg3,
data.arg4,data.arg5,data.arg6);
});
然后导出excel的任务应该是在exportReport里完成的
function exportReport(provinceID, fromDate, toDate, type, year, month)
{
var data = "provinceID=" + provinceID;
data += "&from=" + fromDate;
data += "&till=" + toDate;
data += "&type=" + type;
data += "&year=" + year;
data += "&month=" + month;
var option = {
url: "ExportReport.action",
data:data,
success: function(res, textStatus){
if (res.match("^http"))
window.location.href = res;
else
alert(res);
},
error:function(res,textStatus){
alert(textStatus);
}
};
$.ajax(option);
}
绑定导出图片的方法如下:
$("#report_image" + i).unbind("click");
$("#report_image" + i).bind("click",
{
chart: chart,
title: title
},function(event){
var data = event.data;
data.chart.exportChart({filename: data.title});
});