2
votes

i need to implement some charts in my project, built in Angular2 (version 2.4.8), i use ng2-charts (version 1.5.0) and the version used of chart.js is 2.5.0. To start, i copied an example code from ng2-charts website and i have no errors, but no charts ... Some breaking changes in ng2-charts with Angular2 ?

My component which use charts : HomeComponent.ts

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

@Component({
    selector: 'pulpe-home-cmp',
    templateUrl: './app/components/Home/HomeView.html'
})
export class HomeComponent {

    constructor(){
        console.log(VERSION.full)
    }

    // Doughnut
    public doughnutChartLabels:string[] = ['Download Sales', 'In-Store Sales', 'Mail-Order Sales'];
    public doughnutChartData:number[] = [350, 450, 100];
    public doughnutChartType:string = 'doughnut';

    // events
    public chartClicked(e:any):void {
        console.log(e);
    }

    public chartHovered(e:any):void {
        console.log(e);
    }
}

View : HomeView.html

<div style="display: block">
    <canvas baseChart
        [data]="doughnutChartData"
        [labels]="doughnutChartLabels"
        [chartType]="doughnutChartType"
        (chartHover)="chartHovered($event)" (chartClick)="chartClicked($event)">                                                                                                 
    </canvas> 
</div>

Systemjs : systemjs.config.js

map: { ...
    'ng2-charts': 'node_modules/ng2-charts'
},
package : {
    'ng2-charts': { main: 'ng2-charts.js', defaultExtension: 'js' }
}

My app module : app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { PulpeAppComponent } from './app.component';
import { HomeComponent } from './components/Home/HomeComponent';
import { MenuBarComponent } from './components/MenuBar/MenuBarComponent';
import { SigninComponent } from './components/Signin/SigninComponent';
import { RouterModule } from '@angular/router'
import { ROUTES } from './app.routes'; // ROUTING HERE!
import { APP_BASE_HREF } from '@angular/common';
import { ChartsModule } from 'ng2-charts';

@NgModule({
    imports: [BrowserModule, RouterModule.forRoot(ROUTES), ChartsModule],
    declarations: [
        PulpeAppComponent,
        MenuBarComponent,
        HomeComponent,
        SigninComponent
    ],
    bootstrap: [PulpeAppComponent],
    providers:[
      {provide: APP_BASE_HREF, useValue : '/' }
    ]
})
export class PulpeModule {
}

index.html :

<script src="node_modules/chart.js/dist/Chart.bundle.js"></script>

I've tried with src/chart.js like in example of website but that make an error (require is not defined) and with dist/Chart.js but same, a.k.a nothing displayed ...

After 4 hours of searching i turn to you... some ideas ? thanks

1
do you see any errors in console?Sajeetharan
Nothing ... it's totally clear about logsMaxime De Sogus

1 Answers

1
votes

I found the answer, it's because i use an external lib (mdbootstrap) wich break some dependencies ... i guess

Thanks