Highcharts: Can I export to the user an Excel or CSV of the raw data driving the chart? -


i have charts generated via highcharts through wp adcenter plugin. want users (admins , subscribers alike) able download raw data driving chart excel or csv, not png, jpg or pdf image of chart. there way without serious modification of code (i'm not php programmer). additional export option feature rolled out in near future?

this jsfiddle create excel highchart. download csv option added export menu works fine. go through , own better.

here code:

/**  * small plugin getting csv of categorized chart  */ (function (highcharts) {      // options     var itemdelimiter = ',',  // use ';' direct import excel         linedelimiter = '\n';      var each = highcharts.each;     highcharts.chart.prototype.getcsv = function () {         var xaxis = this.xaxis[0],             columns = [],             line,             csv = "",              row,             col;          if (xaxis.categories) {             columns.push(xaxis.categories);             columns[0].unshift("");         }         each (this.series, function (series) {             columns.push(series.ydata);             columns[columns.length - 1].unshift(series.name);         });          // transform columns csv         (row = 0; row < columns[0].length; row++) {             line = [];             (col = 0; col < columns.length; col++) {                 line.push(columns[col][row]);             }             csv += line.join(itemdelimiter) + linedelimiter;         }         return csv;     };     }(highcharts));  // want add "download csv" exporting menu. post csv // simple php script returns content-type header  // downloadable file. // source code php script can viewed @  // https://raw.github.com/highslide-software/highcharts.com/master/studies/csv-export/csv.php  highcharts.getoptions().exporting.buttons.contextbutton.menuitems.push({     text: 'download csv',     onclick: function () {         highcharts.post('http://www.highcharts.com/studies/csv-export/csv.php', {             csv: this.getcsv()         });     } });    var chart = new highcharts.chart({      chart: {         renderto: 'container'     },      xaxis: {         categories: ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']     },      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]     }]  });  $('#getcsv').click(function () {     alert(chart.getcsv()); }); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -