I am trying to use Highmaps in an angular-cli app with angular2-highcharts package.
I want to use a specific map (http://code.highcharts.com/mapdata/custom/world.js) that I saved into my assets/map
directory, and linked in .angular-cli.json
(apps[0].scripts).
NgModule
import { ChartModule } from 'angular2-highcharts';
...
imports: [
ChartModule.forRoot(
require('highcharts/highmaps'),
),
}
component.ts:
const Highcharts = require('highcharts');
this.mapOptions = {
title: {
text: 'Zoom in on country by double click',
},
mapNavigation: {
enabled: false,
enableDoubleClickZoomTo: true
},
colorAxis: {
min: 1,
max: 1000,
type: 'logarithmic',
},
series: [{
data: data.audience.distributionByCountry,
mapData: Highcharts.maps['custom/world'],
joinBy: ['iso-a2', 'code'],
name: 'Population density',
states: {
hover: {
color: '#a4edba',
},
},
tooltip: {
valueSuffix: '/kmĀ²',
},
}],
};
html
The error (generated by Angular's addScript.js
) complains that the Highcharts is not defined.
Out of curiosity I tried to add the following:
Highcharts = Highcharts || {maps: {}};
at the beginning of the map file so see if that was the problem, but it didn't solve the case.
What should I do to get the locally saved map to work?
EDIT
Detailed attempt report
Attempt 1
@NgModule
import { ChartModule } from 'angular2-highcharts';
declare const Highcharts: any;
require('highcharts/modules/map')(Highcharts);
import '../../assets/maps/world.js';
...
imports: [
ChartModule.forRoot(
Highcharts,
),
]
Compile error
Error encountered resolving symbol values statically. Reference to a local (non-exported) symbol 'Highcharts'. Consider exporting the symbol (position 21:15 in the original .ts file), resolving symbol InsightsModule in /Users/armo/Code/origami/src/app/insights/insights.module.ts
Attempt 2
import { ChartModule } from 'angular2-highcharts';
import * as Highcharts from 'highcharts';
import '../../assets/maps/world.js';
Runtime error
ERROR Error: Uncaught (in promise): ReferenceError: Highcharts is not defined ReferenceError: Highcharts is not defined