Angular2和ng2图表不显示任何图形

时间:2017-03-01 01:57:56

标签: angular chart.js ng2-charts

我需要在我的项目中实现一些图表,内置在Angular2(版本2.4.8)中,我使用ng2-charts(版本1.5.0),使用chart.js的版本是2.5.0。 首先,我从ng2-charts网站复制了一个示例代码,我没有错误,但是没有图表...使用Angular2在ng2-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);
    }
}

查看: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' }
}

我的应用模块: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>

我已尝试使用src / chart.js,例如网站示例,但是会产生错误(需要未定义)和dist / Chart.js但是相同,也就是没有显示......

经过4个小时的搜索,我转向你...一些想法?感谢

1 个答案:

答案 0 :(得分:1)

我找到了答案,这是因为我使用外部lib(mdbootstrap)打破了一些依赖...我想

由于