Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including angular-highcharts with all npm packages installed. Try it out:

require("@angular/common/package.json"); // @angular/common is a peer dependency. require("@angular/core/package.json"); // @angular/core is a peer dependency. var angularHighcharts = require("angular-highcharts")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

angular-highcharts v7.2.0

angular-highcharts

NPM version NPM downloads Build Status

This is a Highcharts directive for Angular.

Requirements

Warning: This version (7.x.x) of angular-highcharts only runs with versions of Highcharts greater than 7. And also be sure to remove @types/highcharts from your dependencies.

{
  "angular": ">=7.0.0",
  "highcharts": ">=7.0.2"
}

Installation

yarn

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

npm

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

angular5 & angular6 support

For angular5 and angular6 you have to install a specific version of angular-highcharts.

# angular5
yarn add angular-highcharts@5
npm i angular-highcharts@5

# angular6
yarn add angular-highcharts@6
npm i angular-highcharts@6

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: Options)

Properties

ref: Highcharts.ChartObject;

Deprecated. Please use ref$.

ref$: Observeable<Highcharts.ChartObject>

Observeable that emits a 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

addSeries(series: ChartSerie): void

Adds a series to the chart

removeSeries(seriesIndex: number): void

Remove series from the chart

StockChart

The Chart object.

Type: class

Constructor

new StockChart(options);

Properties

ref: Highstock.ChartObject;

Deprecated. Please use ref$.

ref$: Observeable<Highstock.ChartObject>

Observeable that emits a HighstockChartObject

MapChart

The Chart object.

Type: class

Constructor

new MapChart(options);

Properties

ref;

Deprecated. Please use ref$.

ref$;

Observeable that emits a HighmapsChartObject

Using Highcharts modules

To use Highcharts modules you have to import them and provide them in a factory (required for aot). You can find the list of available modules in the highcharts folder ls -la node_modules/highcharts/modules.

Hint: Highcharts-more is a exception, you find this module in the root folder. Don't forget to use the modules with the .src suffix, minimized highcharts modules are not importable.

Example

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

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

Highstock & Highmaps support

Highstock

For Highstock support load the following module

// app.module.ts
import * as highstock from 'highcharts/modules/stock.src';

@NgModule({
  providers: [
    { provide: HIGHCHARTS_MODULES, useFactory: () => [ highstock ] }
...
// chart.component.ts
import { StockChart } from 'angular-highcharts';

@Component({
  template: `
    <div [chart]="stockChart"></div>
  `
})
export class ChartComponent {
  stockChart = new StockChart({ options });
}

Example Demo

Highmaps

For Highmaps support load the following module

// app.module.ts
import * as highmaps from 'highcharts/modules/map.src';

@NgModule({
  providers: [
    { provide: HIGHCHARTS_MODULES, useFactory: () => [ highmaps ] }
...
// chart.component.ts
import { MapChart } from 'angular-highcharts';

@Component({
  template: `
    <div [chart]="mapChart"></div>
  `
})
export class ChartComponent {
  mapChart = new MapChart({ options });
}

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 });

This is very useful when using gauge chart type.

Demo

License

MIT © Felix Itzenplitz

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free