百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

angular2-highcharts

> 前端框架
开源

:bar_chart: :chart_with_upwards_trend: 适用于 Angular 项目的 Highcharts

374 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

:bar_chart: :chart_with_upwards_trend: 适用于 Angular 项目的 Highcharts

⚠️ Not supported anymore.

Consider using the offical Highcharts wrapper for Angular

angular2-highcharts

Highcharts chart components for Angular apps. Live Demo

Table of Contents

  • Setting Up
  • Install angular2-highcharts
  • Setup App @NgModule
  • Usage
  • Basic Usage
    • Setup App Module
    • Create First Chart Component
  • Handling Events
    • Chart Events
    • Series Events
    • Point Events
    • Axis Events
  • Dynamic Interaction with Chart Object
  • Highstock
  • Highmaps
  • Add Highcharts Modules
  • Access to the Highcharts Static API
  • More Examples
  • FAQ
  • License

Setting Up

Install angular2-highcharts

bash
npm install angular2-highcharts --save

Setup App @NgModule

typescript
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ChartModule } from 'angular2-highcharts';
import { App } from './App';

@NgModule({
    imports: [
      BrowserModule, 
      ChartModule.forRoot(require('highcharts'))
    ],
    declarations: [App],
    bootstrap: [App]
})
export class AppModule {}

For angular-cli and other Webpack environments

No any additional setup needed

For SystemJS environment

You should add appropriate mapping to your systemjs.config.js

javascript
...
map: {
  ...
  'angular2-highcharts': 'node_modules/angular2-highcharts',
  'highcharts': 'node_modules/highcharts',
}
...
packages: {
  ...
  highcharts: {
    main: './highcharts.js',
    defaultExtension: 'js'
  },
  'angular2-highcharts': {
    main: './index.js',
    defaultExtension: 'js'
  }
}

Usage

Basic Usage

Create First Chart Component

Main charts functionality provided by the chart component and its options property.

typescript
import { Component } from '@angular/core';

@Component({
    selector: 'simple-chart-example',
    template: `
        
    `
})
export class App {
    constructor() {
        this.options = {
            title : { text : 'simple chart' },
            series: [{
                data: [29.9, 71.5, 106.4, 129.2],
            }]
        };
    }
    options: Object;
}

Live Demo

Handling Events

Highcharts itself provides bunch of events, and you still can use them with angular2-higcharts via the options property of the chart component. But it is not an angular way to handle events like this. So that angular2-higcharts provides EventEmitter wrappers for highcharts events. ChartEvent is an angular2-higcharts class which simply wraps original Highcharts events (chartEvent.originalEvent) and adds event handler context (chartEvent.context) since it differs depending on events.

Chart Events

All the events from the options.chart.events are available as output properties of the chart component.

xml
 
typescript
onChartSelection (e) {
  this.from = e.originalEvent.xAxis[0].min.toFixed(2);
  this.to = e.originalEvent.xAxis[0].max.toFixed(2);
}

Live Demo

Series Events

To use series events the same way you need to add the series component as a child of your chart. The only purpose of this auxiliary component is to provide access to options.plotOptions.series.events API

xml

    
    

{{serieName}} is hovered
typescript
onSeriesMouseOver (e) {
  this.serieName = e.context.name;
}

Live Demo

Point Events

Similary you can use the point to access to options.plotOptions.series.point.events API.

xml

    
        
    

{{point}} is selected

Live Demo

Axis Events

Similary you can use the xAxis or yAxes to access to options.xAxis.events or options.yAxis.events API.

xml

     
     

{{minX}} - {{maxX}}

{{minY}} - {{maxY}}
typescript
onAfterSetExtremesX (e) {
  this.minX = e.context.min;
  this.maxX = e.context.max;
}
onAfterSetExtremesY (e) {
  this.minY = e.context.min;
  this.maxY = e.context.max;
}

Live Demo

Dynamic Interaction with Chart Object

angular2-higcharts provides possibility to interact with native HighchartsChartObject chart object.

typescript
@Component({
    selector: 'my-app',
    directives: [CHART_DIRECTIVES],
    template: `
      
      
    `
})
class AppComponent {
    constructor() {
        this.options = {
          chart: { type: 'spline' },
          title: { text : 'dynamic data example'}
          series: [{ data: [2,3,5,8,13] }]
        };
        setInterval(() => this.chart.series[0].addPoint(Math.random() * 10), 1000);
    }
    chart : Object;
    options: Object;
    saveInstance(chartInstance) {
        this.chart = chartInstance;
    }
}

Live Demo

Highstock

Also you need to change your @NgModule setup.

diff
...
@NgModule({
    ...
    imports: [
      BrowserModule, 
      ChartModule.forRoot(
-       require('highcharts'),
+       require('highcharts/highstock')
      )
    ]
})

Live Demo

Highmaps

Also you need to change your @NgModule setup.

diff
...
@NgModule({
    ...
    imports: [
      BrowserModule, 
      ChartModule.forRoot(
-       require('highcharts'),
+       require('highcharts/highmaps')
      )
    ],
})

Live Demo

Add Highcharts Modules

Any other modules like highcharts-3d, highcharts-exporintg and etc. can be also added in @NgModule after main chart module

diff
...
@NgModule({
    ...
    imports: [
      BrowserModule, 
      ChartModule.forRoot(
        require('highcharts'),
+       require('highcharts/highchart-3d'),
+       require('highcharts/modules/exporting')
      )
    ],
})

Check out structure of the node-modules/highcharts folder to find necessary module.

Live Demo

Access to the Highcharts Static API

diff
...
const Highcharts = require('highcharts');

Highcharts.setOptions({
  colors: ['#50B432']
});

@NgModule({
    ...
    imports: [
      BrowserModule, 
      ChartModule.forRoot(
-       require('highcharts'),
+       Highcharts
      )
    ],
})

Live Demo

##More Examples

Here are some common charts examples with Webpack integration https://github.com/gevgeny/angular2-highcharts/tree/master/examples/webpack

##FAQ

Why don't my series, title, axes and etc redraw after I update initial options ?

Because angular-highcharts is just a thin wrapper of the [Highcharts](http:/ /www.highcharts.com/) library and doesn't bind to initial options. I understand that you expect more angular-way behaviour like data binding with appropriate redrawing. But it is barely possible to implement it without redundant complications and performance decrease because almost all options can be dynamic. So my idea was to avoid any additional logic more than just a sugar (like events for series and options). In the other hand Highcharts has great API for dynamic manipulations with chart and angular-highcharts provides you access to the original chart object.

License

MIT @ Eugene Gluhotorenko

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptangularangular2-highchartschart-componentcharting-library

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架