highcharts / export-csv

Highcharts plugin to export chart data to CSV
http://www.highcharts.com/plugin-registry/single/7/Export-CSV
MIT License
76 stars 95 forks source link

Can't change dateFormat #118

Closed leongaban closed 7 years ago

leongaban commented 7 years ago

Here is a function that explicitly changes the dateFormat on the chart object before it gets the downloadCSV method called on it.

Next in the first screenshot, you can see that this.options.exporting has the new dateFormat I added.

However by line 48 options.dateFormat is still undefined so then it always defaults to '%Y-%m-%d %H:%M:%S'

this.downloadCsv = () => {
        const chart = ChartExport.getChart();
        chart.options.exporting.filename = createFileName(chart);
        chart.options.exporting.dateFormat = '%H:%M:%S';
        console.log('chart', chart)
        chart.downloadCSV();
        this.$close();
    };

screen shot 2017-01-25 at 11 51 49 am

screen shot 2017-01-25 at 11 51 35 am

Love the plugin btw! Just working out the final kinks in formatting the CSV.

leongaban commented 7 years ago

Not a bug, needed to set the dateFormat on a new csv key for exporting

exporting.csv.dateFormat Which date format to use for exported dates on a datetime X axis. See Highcharts.dateFormat.

exporting: {
    allowHTML: true,
    enabled: false,
    sourceWidth: 640,
    sourceHeight: 400,
    csv: {
        dateFormat: '%Y-%m-%d'
    },
    chartOptions: {
        title: {
            text: null
        }
    }
},