我按照https://www.npmjs.com/package/angular-highcharts的安装和示例进行了操作,但是,我收到错误:
node_modules / angular-highcharts / chart.d.ts(1,23)中的错误:错误TS2688:找不到' highcharts'
我正在使用angular-cli:
Angular CLI: 1.6.0
Node: 9.3.0
OS: darwin x64
Angular: 5.1.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.6.0
@angular-devkit/build-optimizer: 0.0.35
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.41
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.0
@schematics/angular: 0.1.10
@schematics/schematics: 0.0.10
typescript: 2.4.2
webpack: 3.10.0
app.module.ts:
...
import {ChartComponent} from "./chart/chart.component";
import {ChartModule} from "angular-highcharts";
@NgModule({
declarations: [
AppComponent,
BatteryChargingDetailsComponent,
ChartComponent
],
imports: [
BrowserModule,
HttpClientModule,
ChartModule,
FormsModule,
ReactiveFormsModule,
MultiselectDropdownModule,
RouterModule.forRoot(ROUTES)
],
providers: [
AuthService
],
bootstrap: [AppComponent]
})
export class AppModule {
private static NgxAdminLteModule: any;
}
的package.json
{
"name": "revolts-web",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"build:prod:pre": "rm -rf dist && node ./replace.build.js",
"build:prod:auto-version": "npm version patch && npm run build:prod:pre",
"build:prod:build": "ng build --prod",
"build:prod:package": "cd dist && zip -r orcas-ui-$npm_package_version.zip .",
"build:prod": "npm run build:prod:pre && npm run build:prod:build && npm run build:prod:package"
},
"private": true,
"dependencies": {
"@angular/animations": "^5.0.0",
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/http": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"admin-lte": "^2.4.2",
"angular-2-dropdown-multiselect": "^1.6.3",
"angular-admin-lte": "^0.2.5",
"angular-auth0": "^3.0.0",
"angular-highcharts": "^5.2.0",
"highcharts": "^6.0.4",
"auth0-js": "^9.0.2",
"core-js": "^2.4.1",
"rxjs": "^5.5.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.6.0",
"@angular/compiler-cli": "^5.0.0",
"@angular/language-service": "^5.0.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.4.2"
}
}
在谷歌搜索后,我发现有人添加了#34; @ types / highcharts":" ^ 5.0.12"到"依赖"在package.json中。 ..和npm安装后 ng serve - >这里没有错误。
谷歌控制台上的我得到了:
scripts.bundle.js:11 Uncaught Error: Highcharts error #16: www.highcharts.com/errors/16
at Object.a.error (scripts.bundle.js:11)
at eval (highcharts.js:8)
at eval (highcharts.js:9)
at eval (highcharts.js:8)
at eval (highcharts.js:8)
at Object.../../../../highcharts/highcharts.js (vendor.bundle.js:336)
at __webpack_require__ (inline.bundle.js:55)
at eval (angular-highcharts.es5.js:8)
at Object.../../../../angular-highcharts/angular-highcharts.es5.js (vendor.bundle.js:39)
at __webpack_require__ (inline.bundle.js:55)
a.error @ scripts.bundle.js:11
(anonymous) @ highcharts.js:8
(anonymous) @ highcharts.js:9
(anonymous) @ highcharts.js:8
(anonymous) @ highcharts.js:8
我的问题在哪里?
答案 0 :(得分:14)
npm install --save @ types / highcharts
答案 1 :(得分:0)
您可以尝试以下app.module
import {ChartModule} from "angular2-highcharts";
import {HighchartsStatic} from "angular2-highcharts/dist/HighchartsService";
export function highchartsFactory() {
var hc = require('highcharts');
var hcm = require('highcharts/highcharts-more');
var exp = require('highcharts/modules/exporting');
var drill = require('highcharts/modules/drilldown');
hcm(hc);
exp(hc);
drill(hc)
return hc;
}
@NgModule({
..
providers: [
{
provide: HighchartsStatic,
useFactory: highchartsFactory
}
],
})
我已经做了这么久,所以如果有任何问题请原谅我,但它适用于Angular五角形甜甜圈
答案 2 :(得分:0)
您需要添加键入内容以使其能够显示高图,您可以通过以下命令添加:
npm install --save @types/highcharts
答案 3 :(得分:-1)
我注释掉了'node_modules / angular-highcharts / chart.d.ts'文件的第一行:
<reference type="highcharts">
这可以防止错误,并且模块似乎正常工作。