【发布时间】:2018-11-24 09:24:08
【问题描述】:
在我的 angular-cli 6 项目中,我使用 highcharts 来创建实心量规。但是我收到了这个错误https://www.highcharts.com/errors/17。所以为了工作,我必须将 highcharts-more.js 文件添加到我的组件中。
我正在为 highcharts 使用以下 npm 包。
- npm install highcharts
- npm install --save-dev @types/highcharts(因为当我尝试导入 highcharts 时 VS Code 建议我)
这是我的组件的代码以及导入:
import {
AfterViewInit,
Component,
ElementRef,
Injector,
OnInit,
ViewChild
} from '@angular/core';
import * as Highcharts from 'highcharts';
import { chart } from 'highcharts';
import highchartsMore from 'highcharts/highcharts-more';
import { AbstractDashboardCard } from '../../models/abstract-dashboard-card';
import { DashboardCard } from '../../models/dashboard-card';
highchartsMore(Highcharts);
@Component({
selector: 'app-luchtkwaliteit',
templateUrl: './luchtkwaliteit.component.html',
styleUrls: ['./luchtkwaliteit.component.css']
})
export class LuchtkwaliteitComponent extends AbstractDashboardCard
implements OnInit, AfterViewInit {
@ViewChild('chartTarget') chartTarget: ElementRef;
chart: Highcharts.ChartObject;
constructor(private injector: Injector) {
super(
injector.get(DashboardCard.metadata.NAME),
injector.get(DashboardCard.metadata.SOURCE),
injector.get(DashboardCard.metadata.COLS),
injector.get(DashboardCard.metadata.ROWS)
);
}
ngOnInit() {}
ngAfterViewInit() {
const gaugeOptions = {
chart: {
type: 'solidgauge'
},
title: null,
pane: {
center: ['50%', '85%'],
size: '140%',
startAngle: -90,
endAngle: 90,
background: {
backgroundColor: '#EEE',
innerRadius: '60%',
outerRadius: '100%',
shape: 'arc'
}
},
tooltip: {
enabled: false
},
// the value axis
yAxis: {
stops: [
[0.1, '#55BF3B'], // green
[0.5, '#DDDF0D'], // yellow
[0.9, '#DF5353'] // red
],
lineWidth: 0,
minorTickInterval: null,
tickAmount: 2,
min: 0,
max: 200,
title: {
y: -70,
text: 'Speed'
},
labels: {
y: 16
}
},
plotOptions: {
solidgauge: {
dataLabels: {
y: 5,
borderWidth: 0,
useHTML: true
}
}
},
credits: {
enabled: false
},
series: [
{
name: 'Speed',
data: [80],
dataLabels: {
format:
'<div style="text-align:center"><span style="font-size:25px;color: black' +
'">{y}</span><br/>' +
'<span style="font-size:12px;color:silver">km/h</span></div>'
},
tooltip: {
valueSuffix: ' km/h'
}
}
]
};
this.chart = chart(this.chartTarget.nativeElement, gaugeOptions);
}
}
所以我已经对如何添加 highcharts-more 进行了一些调查,但没有找到解决方案。我发现的东西:
- npm install highcharts-more 但它已被弃用所以我没有使用它 https://www.npmjs.com/package/highcharts-more
- 从“highcharts/highcharts-more”导入 * 作为 highchartsMore; TS 错误“node_modules/@types/highcharts/highcharts-more”解析为非模块实体,无法使用此构造导入。
- 导入 * as highchartsMore from 'highcharts'; highchartsMore(Highcharts) 上的 TS 错误;无法调用其类型缺少调用签名的表达式。 “静态”类型没有兼容的调用签名。
- highcharts-angular 没有使用它,因为 angular 6 有问题 https://github.com/highcharts/highcharts-angular/issues/29
【问题讨论】:
标签: javascript angular typescript highcharts