关于Highcharts的详细情况,在另一篇文章中有介绍。这篇主要介绍如何利用插件下载excel文件。
插件:
<script src="http://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/modules/exporting.js"></script> <script src="../cn_js/export-csv.js"></script>
export-csv.js文件内容:
/** * A Highcharts plugin for exporting data from a rendered chart as CSV, XLS or HTML table * * Author: Torstein Honsi * Licence: MIT * Version: 1.4.2 */ /*global Highcharts, window, document, Blob */ (function (factory) { if (typeof module === 'object' && module.exports) { module.exports = factory; } else { factory(Highcharts); } })(function (Highcharts) { 'use strict'; var each = Highcharts.each, pick = Highcharts.pick, seriesTypes = Highcharts.seriesTypes, downloadAttrSupported = document.createElement('a').download !== undefined; Highcharts.setOptions({ lang: { downloadCSV: 'Download CSV', downloadXLS: 'Download XLS', viewData: 'View data table' } }); /** * Get the data rows as a two dimensional array */ Highcharts.Chart.prototype.getDataRows = function () { var options = (this.options.exporting || {}).csv || {}, xAxis = this.xAxis[0], rows = {}, rowArr = [], dataRows, names = [], i, x, xTitle = xAxis.options.title && xAxis.options.title.text, // Options dateFormat = options.dateFormat || '%Y-%m-%d %H:%M:%S', columnHeaderFormatter = options.columnHeaderFormatter || function (series, key, keyLength) { return series.name + (keyLength > 1 ? ' ('+ key + ')' : ''); }; // Loop the series and index values i = 0; each(this.series, function (series) { var keys = series.options.keys, pointArrayMap = keys || series.pointArrayMap || ['y'], valueCount = pointArrayMap.length,

本文重点讲解如何使用Highcharts的插件来实现图表数据导出为Excel文件的功能,包括设置插件和自定义右上角菜单的文字以适应中英文切换的需求。
最低0.47元/天 解锁文章
1503

被折叠的 条评论
为什么被折叠?



