我正在尝试使用Angular项目中的HighMaps创建地图。
不幸的是,highcharts-angular尚未正式更新Angular 6,因此我将通过不同方式创建地图。现在我的代码为highchart-map.component.ts
:
import { map } from 'highcharts';
import * as Highcharts from 'highcharts';
import * as HC_map from 'highcharts/modules/map';
export class HighchartMapComponent implements OnInit {
title = 'Highcharts Demo';
@ViewChild('chartTarget') chartTarget: ElementRef;
chart: Highcharts.ChartObject;
map: any;
ngAfterContentInit() {
//Called after ngOnInit when the component's or directive's content has been initialized.
//Add 'implements AfterContentInit' to the class.
const highMapOpts: Highcharts.MapOptions = {
title: {
text: 'Locations'
},
series: [{
name: 'Basemap',
mapData: '../../assets/maps/us-all-territories.js',
}]
}
this.map = map(this.chartTarget.nativeElement,highMapOpts)
}
}
不幸的是,VSCode抱怨highMapOpts
对象:
[ts] Type '{ title: { text: string; }; series: { name: string; mapData: string; }[]; }' is not assignable to type 'MapOptions'.
我是否正确指定了MapOptions?特别是mapData字段,因为我正在存储从Highmaps - Map Collection检索到的地图js文件。