Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use highcharts with angular 5?

Is there any way to use highcharts.js with angular2 ?Is there any option available instead of highcharts?

like image 930
dhananjay_shingote Avatar asked Mar 01 '16 10:03

dhananjay_shingote


People also ask

Is Highcharts angular free?

We are therefore happy to present to you our official Highcharts Angular wrapper, which is free to use (please note that using Highcharts for commercial projects require a valid license).

Can I use Highchart for free?

Highcharts is free to use for personal projects, school websites, and non-profit organizations.


3 Answers

You could also try angular2-highcharts I implemented.

like image 125
Eugene Gluhotorenko Avatar answered Oct 23 '22 12:10

Eugene Gluhotorenko


I know this question is a bit stale, but is one of the first hits for angular2+highcharts queries... It's pretty simple and straight forward to get highcharts working. Here is a plunker example, https://plnkr.co/edit/8ccBrP?p=preview.

Here is the main logic:

import {
    Component,
    ElementRef,
    AfterViewInit,
    OnDestroy,
    ViewChild
} from '@angular/core';

const Highcharts = require('highcharts/highcharts.src');
import 'highcharts/adapters/standalone-framework.src';

@Component({
    selector: 'my-app',
    template: `
        <div>
            <div #chart></div>
        </div>
    `
})
export class AppComponent implements AfterViewInit, OnDestroy {
  @ViewChild('chart') public chartEl: ElementRef;

  private _chart: any;

  public ngAfterViewInit() {
    let opts: any = {
        title: {
            text: 'Monthly Average Temperature',
            x: -20 //center
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },
        series: [{
            name: 'Tokyo',
            data: [
                7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2,
                26.5, 23.3, 18.3, 13.9, 9.6
            ]
        }]
    };

    if (this.chartEl && this.chartEl.nativeElement) {
        opts.chart = {
            type: 'line',
            renderTo: this.chartEl.nativeElement
        };

        this._chart = new Highcharts.Chart(opts);
    }
  }

  public ngOnDestroy() {
    this._chart.destroy();
  }
}
like image 36
roto Avatar answered Oct 23 '22 11:10

roto


I think that you could try ng2-highchart (https://github.com/Bigous/ng2-highcharts).

See this project for a sample of use: https://github.com/Bigous/angular2-seed-ng2-highcharts.

  • How to set it up in SystemJS configuration: https://github.com/Bigous/angular2-seed-ng2-highcharts/blob/master/src/index.html#L43 and https://github.com/Bigous/angular2-seed-ng2-highcharts/blob/master/tools/config.ts#L108

    <script>
      System.config({
        map: {
          'ng2-highchart': 'node_modules/ng2-highchart'
        },
        (...)
      });
    </script>
    
  • How to configure it within a component: https://github.com/Bigous/angular2-seed-ng2-highcharts/blob/master/src/home/components/home.ts#L10

    import {Component, OnInit} from 'angular2/core';
    import {Http} from 'angular2/http';
    import {Ng2Highcharts, Ng2Highmaps, Ng2Highstocks} from 'ng2-highcharts/ng2-highcharts';
    
    @Component({
      selector: 'home',
      moduleId: module.id,
      templateUrl: './home.html',
      styleUrls: ['./home.css'],
      directives: [Ng2Highcharts, Ng2Highmaps, Ng2Highstocks]
    })
    export class HomeCmp implements OnInit {
      (...)
    }
    
  • How to use it within a component template: https://github.com/Bigous/angular2-seed-ng2-highcharts/blob/master/src/home/components/home.html#L9

    <div [ng2-highcharts]="chartOptions" class="graph"></div>
    
like image 10
Thierry Templier Avatar answered Oct 23 '22 11:10

Thierry Templier