This is a Highcharts directive for Angular.
Do you use Angular 5? Please go here.
{
"angular": ">=4.0.0",
"highcharts": ">=5.0.0"
}
# install angular-highcharts and highcharts
yarn add angular-highcharts@4 highcharts
# install highcharts typings
yarn add --dev @types/highcharts
# install angular-highcharts and highcharts
npm i --save angular-highcharts@4 highcharts
# install highcharts typings
npm i --save-dev @types/highcharts
// 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));
}
}
The Chart object.
Type: class
new Chart(options: HighchartsOptions)
ref: HighchartsChartObject
References to the HighchartsChartObject - Offical Chart API Docs
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
To use Highcharts modules you have to import them and provide them in a factory (required for aot).
// 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
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 });
- API Docs
- Highstocks support
- Highmaps support
MIT © Felix Itzenplitz