score:1

Accepted answer

To use HighChart in Ionic 2 you must:

  • installation

    npm install highcharts --save
    
  • Load module on the page where you want to use the charts

    declare var require: any;
    let hcharts = require('highcharts');
    require('highcharts/modules/exporting')(hcharts);`
    
  • On the activity.html page

    <div #graph></div>
    
  • and finally

    initLapChart() {
        hcharts.chart(this.div.nativeElement, {
            chart: {..}
        ... 
    }
    

I hope I was clear.

score:7

You're probably using angular 2 RC. The answer from mharrington was about ionic beta.37 (i guess) which used a beta version of angular 2.

It's updated to ChartModule now. See below or check out the github and their demo (plnkr)

As explained by the angular2-highcharts:

In your @ngModule declaration file (prob app.module.ts)

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ChartModule } from 'angular2-highcharts';
import { App } from './App';

@NgModule({
    imports: [BrowserModule, ChartModule],
    declarations: [App],
    bootstrap: [App]
})
export class AppModule {}

and in your class:

import { Component } from '@angular/core';

@Component({
    selector: 'simple-chart-example',
    template: `
        <chart [options]="options"></chart>
    `
})
export class App {
    constructor() {
        this.options = {
            title : { text : 'simple chart' },
            series: [{
                data: [29.9, 71.5, 106.4, 129.2],
            }]
        };
    }
    options: HighchartsOptions;
}

Also, depending on what version you're using, you might have to change the import from

import { ChartModule } from 'ng2-charts';

To

import { ChartModule } from 'ng2-charts/components/charts/charts';

Because of this issue (#440)

and keep in mind that the docs could be outdated, depending on version, if binding to [datasets] fails, bind to [data] Source: ng2-charts - Can't bind to 'datasets' since it isn't a known property of 'base-chart'


Related Query

More Query from same tag