Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2 Highcharts

I am using Ionic 2 framework and want to implement highcharts.

I followed this step https://forum.ionicframework.com/t/ionic-2-and-highcharts-modules/59365/2 from mharington (ionic team) to setup my first high chart.

The error I get is I can't import it but I installed with node modules

Error

enter image description here

 angular2-highcharts include in my node_modules

please help

like image 350
Royce Avatar asked Feb 06 '23 21:02

Royce


1 Answers

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'

like image 92
Ivar Reukers Avatar answered Feb 13 '23 05:02

Ivar Reukers