我需要在我的项目中实现一些图表,该图表(版本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个小时后,我转向您...一些想法?谢谢
我找到了答案,这是因为我使用了外部lib(mdbootstrap)break break break break break break break with一些依赖关系...我猜
谢谢