2

I'm using angular-5,angular2-highcharts version 0.5.5 and highcharts version 6.0.7.

I want to add in my html in not in the chart a button for download the chart in png or csv.

Png one works fine, but I can't got it with csv:

This is my code:

downloadPng(): void {   //this one works
   this.chart.exportChart({
      type: 'image/png',
      filename: this.title
    });
}

downloadCsv(): void {   //this one crashes
   this.chart.exportChart({
      type: 'text/csv',
      filename: this.title
    },{
      itemDelimiter: ';',
      csv: this.chart.getCSV() 
    });
}

When crashes it redirects to

https://export.highcharts.com/

with this text

unexpected return from chart generation - please check your input data

I think I need to do something else for csv export. Can anybody help me?

cucuru
  • 3,456
  • 8
  • 40
  • 74

1 Answers1

4

You need the export-data module. It extends a chart with downloadCSV method.

function downlaodCsv() {
  chart.downloadCSV()
}

live example: http://jsfiddle.net/z1j4enox/

morganfree
  • 12,254
  • 1
  • 14
  • 21
  • is it possible to change file name? – cucuru Apr 23 '18 at 07:21
  • I've just realized I also have trouble with png, because when exporting the chart data is removed (thats not removed with chart.downloadCSV()) could you include how to donwload png in your example, please? – cucuru Apr 23 '18 at 09:01
  • You can set exporting.filename option to change the file name. chart.exportChart() should export the chart to png - see the example http://jsfiddle.net/u32yfm9j/. – morganfree Apr 25 '18 at 10:47
  • thanks but what you post doesn't work in angular. I can filename in png but I can't in csv. Also in angular "exportChart()" removes the chart data. – cucuru Apr 25 '18 at 10:52
  • I suppose it might be the issue with the wrapper if you use one. If you post a live example with minimal and complete code, e.g. on plunkr, I will try to find the solution. – morganfree Apr 25 '18 at 10:55
  • change name in csv is now working, the only remaining problem is exportChart removes data, you can check it by clicking twice to downloadpng button – cucuru Apr 27 '18 at 07:40