如何导入highcharts-更多

时间:2017-11-04 23:37:00

标签: angular highcharts angular2-highcharts

我想使用highcharts中的spiderweb图表,这需要我更多地导入highcharts,但我无法弄清楚如何做到这一点。目前,这就是我从app.module.ts

向我的项目添加高价图表的方法
import { ChartModule } from 'angular2-highcharts';
import { HighchartsStatic } from 'angular2-highcharts/dist/HighchartsService';
import * as Highcharts from 'highcharts/highstock';

imports: [
    ChartModule
]

providers: [{
    provide: HighchartsStatic,
    useValue: Highcharts
}],

当我尝试像这样导入它时:

import * as HighchartsMore from 'highcharts/highcharts-more';

我收到以下错误:

Module '"c:/pdws-view-v2/node_modules/@types/highcharts/highcharts-more"' resolves to a non-module entity and cannot be imported using this construct.

有什么想法吗?

5 个答案:

答案 0 :(得分:27)

您无需使用外部模块即可在Angular应用中使用highcharts或任何扩展程序包。您需要执行的所有操作npm install --save highcharts highcharts-more然后在您的组件中以及其他导入包括:

// HIGHCHARTS
import * as Highcharts from 'highcharts';
declare var require: any;
require('highcharts/highcharts-more')(Highcharts);
require('highcharts/modules/solid-gauge')(Highcharts);
require('highcharts/modules/heatmap')(Highcharts);
require('highcharts/modules/treemap')(Highcharts);
require('highcharts/modules/funnel')(Highcharts);
let chartHolder;

和示例用法:

ngOnInit() {
  chartHolder = Highcharts.chart('container', newOptions);
}

您可以更新图表选项:

updateChart(newOptions) {
  chartHolder.update(newOptions);
}

答案 1 :(得分:2)

已弃用highcharts-more npm软件包-无需安装。只需确保已安装highcharts

解决方案:

import * as Highcharts from 'highcharts';
import more from 'highcharts/highcharts-more';
more(Highcharts);

答案 2 :(得分:0)

使用add-highcharts-modules并将其更新为蜘蛛图

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { NgModule, Component }    from '@angular/core';
import { BrowserModule }          from '@angular/platform-browser';
import { ChartModule }            from 'angular2-highcharts'; 

@Component({
    selector: 'my-app',
    styles: [`
      chart {
        display: block;
      }
    `],
    template: `<chart [options]="options"></chart>`
})
class AppComponent {
    constructor() { 
        this.options = {

            chart: {
        polar: true,
        type: 'line'
    },

    title: {
        text: 'Budget vs spending',
        x: -80
    },

    pane: {
        size: window.innerWidth * .80
    },

    xAxis: {
        categories: ['Sales', 'Marketing', 'Development', 'Customer Support',
                'Information Technology', 'Administration'],
        tickmarkPlacement: 'on',
        lineWidth: 0
    },

    yAxis: {
        gridLineInterpolation: 'polygon',
        lineWidth: 0,
        min: 0
    },

    tooltip: {
        shared: true,
        pointFormat: '<span style="color:{series.color}">{series.name}: <b>${point.y:,.0f}</b><br/>'
    },

    legend: {
        align: 'right',
        verticalAlign: 'top',
        y: 70,
        layout: 'vertical'
    },

    series: [{
        name: 'Allocated Budget',
        data: [43000, 19000, 60000, 35000, 17000, 10000],
        pointPlacement: 'on'
    }, {
        name: 'Actual Spending',
        data: [50000, 39000, 42000, 31000, 26000, 14000],
        pointPlacement: 'on'
    }]



         };
    };
    options: Object;
}

@NgModule({
  imports: [
    BrowserModule, 
    ChartModule.forRoot(
      require('highcharts'),
      require('highcharts/modules/exporting'),
      require('highcharts/highcharts-more'),
    )
  ],
  declarations: [AppComponent],
  bootstrap:    [AppComponent]
})
class AppModule { }


platformBrowserDynamic().bootstrapModule(AppModule);

Plunker

答案 3 :(得分:-1)

不确定是否应该导入。在我看来,根据库的npm页面(https://www.npmjs.com/package/highcharts-more)中的用法,您只需将其包含在代码库中,使用<script>标记,或将其路径添加到{{1 scripts中的数组。

答案 4 :(得分:-1)

真是一团糟:)现在按照doku中的说明将其禁用:

Highcharts.chart(container, {
    title:{
        text: undefined
    },
    subtitle:{
        text: undefined
    }
.....