gevgeny / angular2-highcharts

:bar_chart: :chart_with_upwards_trend: Highcharts for your Angular project
MIT License
380 stars 113 forks source link

Access to Highcharts.Static methods in type-safe way? #170

Open leonyah opened 7 years ago

leonyah commented 7 years ago

Could you share an example on how to access the highchart static methods, such as Highcharts.getOptions().colors ? Furthermore, how to do it using highcharts type definitions. I can't figure out how to convert HighchartsStatic to Highchart.Static type definition. Thank you.

I did "npm install --save @types/highcharts", but still having trouble figuring out how to cast to Highcharts.Static

leonyah commented 7 years ago

I found a solution, but would appreciate a confirmation whether I did this right, especially the casting to Highcharts.Static on this line: this.hoptions = (<Highcharts.Static> highchartStatic).getOptions()

import { Component } from '@angular/core';
import {HighchartsStatic} from 'angular2-highcharts/dist/HighchartsService';
import * as Highcharts from "highcharts";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
    constructor(highchartStatic:HighchartsStatic) {
        this.options = {
            title : { text : 'simple chart' },
            series: [{
                data: [29.9, 71.5, 106.4, 129.2],
            }]
        };
        this.hoptions = (<Highcharts.Static> highchartStatic).getOptions();
    }
    options: Highcharts.Options;
    hoptions:Highcharts.Options;
}