【发布时间】:2023-04-10 09:19:01
【问题描述】:
我正在尝试在带有 angular2-highcharts 包的 angular-cli 应用程序中使用 Highmaps。
我想使用我保存到我的assets/map 目录中并链接到.angular-cli.json (apps[0].scripts) 的特定地图 (http://code.highcharts.com/mapdata/custom/world.js)。
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
错误(由 Angular 的 addScript.js 生成)抱怨 Highcharts 未定义。
出于好奇,我尝试添加以下内容:
Highcharts = Highcharts || {maps: {}};
在地图文件的开头,看看是否是问题所在,但并没有解决问题。
我应该怎么做才能让本地保存的地图工作?
编辑
详细的尝试报告
尝试 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,
),
]
编译错误
静态解析符号值时遇到错误。对本地(非导出)符号“Highcharts”的引用。考虑导出符号(原始 .ts 文件中的位置 21:15),解析 /Users/armo/Code/origami/src/app/insights/insights.module.ts 中的符号 InsightsModule
尝试 2
import { ChartModule } from 'angular2-highcharts';
import * as Highcharts from 'highcharts';
import '../../assets/maps/world.js';
运行时错误
错误错误:未捕获(承诺):ReferenceError:未定义Highcharts ReferenceError: Highcharts 未定义
【问题讨论】:
标签: angular highcharts highmaps