Rectangle 27 1

javascript How I can customize the file name when exporting using the plug in CSV in Highcharts?


Highcharts.post('http://www.highcharts.com/studies/csv-export/csv.php', {
                csv: this.getCSV()
            });
header('Content-disposition: attachment;filename=chart.csv');

As you see the URL is coded in there to csv.php. Now reading through that file the PHP source code is also available. And its quite simple.

From this page you can change the URL from the following line. (Line 48 on GIT)

From what I can tell on the javascript plugin the URL is coded into the file. Therefore the PHP file that emits the CSV file for download controls the details of the CSV file. To get around this you could easily modify the plugin and change the URL then host your own CSV generation tool that emits the file name you wish in any format. Todo this you must get the source for the javascript plugin, and the source for the PHP file.

Now doing this means you must be hosting a PHP server (you can rewrite this in other languages) and you must use your copy of the javascript file.

Now in this file you will see the file name is statically set to chart.csv on line 10.

You can simply change the filename=chart.csv to anything you wish.

Note