You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@echarts.apache.org by GitBox <gi...@apache.org> on 2018/05/29 09:19:10 UTC

[GitHub] crendy commented on issue #4114: 关于echarts的dataview功能

crendy commented on issue #4114: 关于echarts的dataview功能
URL: https://github.com/apache/incubator-echarts/issues/4114#issuecomment-392710083
 
 
   通过自定义tool来解决导出excel。
   关键步骤:读取chart里面的x/y轴数据--拼装成html格式--定义按钮打开链接
   举例:
   
   myTool1: {
   --
     | show: true,
     | title: '导出Excel',
     | icon: 'path://M432.45,595.444c0,2.177-4.661,6.82-11.305,6.82c-6.475,0-11.306-4.567-11.306-6.82s4.852-6.812,11.306-6.812C427.841,588.632,432.452,593.191,432.45,595.444L432.45,595.444z M421.155,589.876c-3.009,0-5.448,2.495-5.448,5.572s2.439,5.572,5.448,5.572c3.01,0,5.449-2.495,5.449-5.572C426.604,592.371,424.165,589.876,421.155,589.876L421.155,589.876z M421.146,591.891c-1.916,0-3.47,1.589-3.47,3.549c0,1.959,1.554,3.548,3.47,3.548s3.469-1.589,3.469-3.548C424.614,593.479,423.062,591.891,421.146,591.891L421.146,591.891zM421.146,591.891',
     | onclick: function (mychart){
     | var option = mychart.getOption();
     | var title = option.title[0].text;
     | var tmp = title.split("-");
     | var dateTemp = tmp[1]+"-"+tmp[2]+"-"+tmp[3]+" ";
     | var series = option.series;
     | var axisData = option.xAxis[0].data;
     |  
     | var excel = '<table>';
     | //设置表头
     | var row = "<tr>"+ '<td>时间</td>'
     | + '<td>' + series[0].name + '</td>'
     | + '<td>' + series[1].name + '</td>'
     | + '</tr>';
     | excel+=row;
     | for (var i = 0, l = axisData.length; i < l; i++) {
     | excel += '<tr>'
     | + '<td>' + dateTemp+axisData[i] + '</td>'
     | + '<td>' + series[0].data[i] + '</td>'
     | + '<td>' + series[1].data[i] + '</td>'
     | + '</tr>';
     | }
     | excel += '</table>';
     | var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
     | excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
     | excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel';
     | excelFile += '; charset=UTF-8">';
     | excelFile += "<head>";
     | excelFile += "<!--[if gte mso 9]>";
     | excelFile += "<xml>";
     | excelFile += "<x:ExcelWorkbook>";
     | excelFile += "<x:ExcelWorksheets>";
     | excelFile += "<x:ExcelWorksheet>";
     | excelFile += "<x:Name>";
     | excelFile += "{worksheet}";
     | excelFile += "</x:Name>";
     | excelFile += "<x:WorksheetOptions>";
     | excelFile += "<x:DisplayGridlines/>";
     | excelFile += "</x:WorksheetOptions>";
     | excelFile += "</x:ExcelWorksheet>";
     | excelFile += "</x:ExcelWorksheets>";
     | excelFile += "</x:ExcelWorkbook>";
     | excelFile += "</xml>";
     | excelFile += "<![endif]-->";
     | excelFile += "</head>";
     | excelFile += "<body>";
     | excelFile += excel;
     | excelFile += "</body>";
     | excelFile += "</html>";
     |  
     | var uri = 'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelFile);
     |  
     | var link = document.createElement("a");
     | link.href = uri;
     |  
     | link.style = "visibility:hidden";
     | link.download =  title+"data.xls";
     |  
     | document.body.appendChild(link);
     | link.click();
     | document.body.removeChild(link);
     |  
     | }
     |  
     | },
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@echarts.apache.org
For additional commands, e-mail: dev-help@echarts.apache.org