I'm using angular2-highcharts and my chart works just fine, but I need to export the chart to XLS.
All I need to achieve this is doing
HighchartsExporting(Highcharts);
HighchartsExportData(Highcharts);
somewhere in the code, and the export options will show up by the chart.
The problem is how to import HighchartsExporting and HighchartsExportData properly, because the standard solution
@NgModule({
imports: [
BrowserModule,
ChartModule.forRoot(
require('highcharts'),
require('highcharts/modules/exporting')
],
won't work with AOT, giving me some "Error encountered resolving symbol values statically" at compile time.
I can get it to work by doing
import * as HichartsExporting from 'highcharts/modules/exporting';
import * as HighchartsExportData from 'highcharts/modules/export-data';
as suggested here, but it gives me 2 errors:
I can get around this by doing
import HichartsExporting = require('highcharts/modules/exporting');
import HighchartsExportData = require('highcharts/modules/export-data');
as suggested here, but after AOT compilation, I get "Uncaught ReferenceError: require is not defined" at runtime.
All solutions seem to work fine in practice, I just can't compile them. Any suggestions are welcome.
Just in case this helps anyone, I couldn't do it using imports. Instead, I had to include the <script src="~/node_modules/highcharts/modules/exporting.js">
tag in my HTML. Since this JS is a self-invoking function, that's all it takes to make it work.