Skip to content

Latest commit

 

History

History
179 lines (140 loc) · 3.7 KB

README.md

File metadata and controls

179 lines (140 loc) · 3.7 KB

angular-highcharts

NPM version NPM downloads Build Status

This is a Highcharts directive for Angular.

Do you use Angular 5? Please go here.

Requirements

{
  "angular": ">=4.0.0",
  "highcharts": ">=5.0.0"
}

Installation

yarn

# install angular-highcharts and highcharts
yarn add angular-highcharts@4 highcharts

# install highcharts typings
yarn add --dev @types/highcharts

npm

# install angular-highcharts and highcharts
npm i --save angular-highcharts@4 highcharts

# install highcharts typings
npm i --save-dev @types/highcharts

Usage Example

// app.module.ts
import { ChartModule } from 'angular-highcharts';

@NgModule({
  imports: [
    ChartModule // add ChartModule to your imports
  ]
})
export class AppModule { }
// chart.component.ts
import { Chart } from 'angular-highcharts';

@Component({
  template: `
    <button (click)="add()">Add Point!</button>
    <div [chart]="chart"></div>
  `
})
export class ChartComponent {
  chart = new Chart({
      chart: {
        type: 'line'
      },
      title: {
        text: 'Linechart'
      },
      credits: {
        enabled: false
      },
      series: [{
        name: 'Line 1',
        data: [1, 2, 3]
      }]
    });
  
  // add point to chart serie
  add() {
    this.chart.addPoint(Math.floor(Math.random() * 10));
  }
}

API Docs

Chart

The Chart object.

Type: class

Constructor

new Chart(options: HighchartsOptions)

Properties

ref: HighchartsChartObject

References to the HighchartsChartObject - Offical Chart API Docs

Methods

addPoint(point: Point, [serieIndex: number = 0]): void

Adds a point to a serie

removePoint(pointIndex: number, [serieIndex: number = 0], [redraw: boolean = true], [shift: boolean = false]): void

Removes a point from a serie

addSerie(serie: ChartSerie): void

Adds a serie to the chart

removeSerie(serieIndex: number): void

Remove serie to the chart

Using Highcharts modules

To use Highcharts modules you have to import them and provide them in a factory (required for aot).

Example

// app.module.ts
import { ChartModule, HIGHCHARTS_MODULES } from 'angular-highcharts';
import exporting from 'highcharts/modules/exporting.src';

export function highchartsModules() {
  // apply Highcharts Modules to this array
  return [ exporting ];
}

@NgModule({
  providers: [
    { provide: HIGHCHARTS_MODULES, useFactory: highchartsModules } // add as factory to your providers
  ]
})
export class AppModule { }

Offical Highcharts NPM Docs: http://www.highcharts.com/docs/getting-started/install-from-npm

Troubleshooting

If you expiring typing errors while you build/serve your angular app the following could be helpful:

// override options type with <any>
chart = new Chart(<any>{ // options here });

Demo

Coming soon

  • API Docs
  • Highstocks support
  • Highmaps support

License

MIT © Felix Itzenplitz