Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export CSV and XLS with external button in Highcharts

As you can see in http://jsfiddle.net/9pxurfga/

I have export buttons outside the chart, and I need to download data to CSV and XLS.

With highcharts export default button everything works fine : PNG, JPEG, CSV, XLS.

With my custom button PNG export is OK, but not the others.

I dont know how to use exportChart function for CSV and XLS, it seems to work only with image, but not with data/text format.

$('#button1').click(function () {
    var chart = $('#container').highcharts();
    chart.exportChartLocal({
        type: 'text/csv'
    });
});
like image 873
kesm0 Avatar asked Oct 16 '25 04:10

kesm0


1 Answers

You could call different function specified in the export-data module named downloadCSV and downloadXLS.

For example (JSFiddle):

// Export TO CSV
$('#button2').click(function () {
    var chart = $('#container').highcharts();
    chart.downloadCSV();
});

 // Export TO XLS
$('#button3').click(function () {
    var chart = $('#container').highcharts();
    chart.downloadXLS();
});

These functions do not use the export server.

Note that to get the same filename output for all buttons I had to add:

exporting: {
    filename: 'chart'
} 
like image 72
Halvor Holsten Strand Avatar answered Oct 18 '25 04:10

Halvor Holsten Strand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!