2016-06-15 5 views
0

では何も表示されません。NG2-チャートは常にソースコードがある私のangular2のjsプロジェクト

私はちょうどhttp://valor-software.com/ng2-charts/に従って、いくつかのチャートを追加したいと思います。 私はbarchartとlinechartを試しました。すべてのことが大丈夫でしたが、グラフは常に何もありません。

The page view The element in chrome developer tools

コンポーネントファイル:

import {Component, OnInit} from '@angular/core' 
import {NgFor, NgClass, NgIf} from "@angular/common"; 
import {CORE_DIRECTIVES, FORM_DIRECTIVES} from "@angular/common" 
import {DataService} from './services/data' 
import {Data} from "./interface/interface"; 
import {CHART_DIRECTIVES} from 'ng2-charts/ng2-charts'; 

@Component({ 
    selector: 'display', 
    directives: [CORE_DIRECTIVES, NgFor, NgClass, NgIf, CHART_DIRECTIVES, FORM_DIRECTIVES], 
    templateUrl: './app/display.component.html', 
    providers: [DataService] 
}) 


export class DisplayComponent implements OnInit { 
    public data; 

    getData(){ 
     this.data = this.dataService.getData()[0] 
    } 


    constructor(private dataService:DataService){ 

    } 

    ngOnInit(){ 
     this.getData() 
    } 

    // lineChart 
    public lineChartData:Array<any> = [ 
     [65, 59, 80, 81, 56, 55, 40], 
     [28, 48, 40, 19, 86, 27, 90] 
    ]; 
    public lineChartLabels:Array<any> = ['January', 'February', 'March', 'April', 'May', 'June', 'July']; 
    public lineChartType:string = 'line'; 
    public pieChartType:string = 'pie'; 

    // Pie 
    public pieChartLabels:string[] = ['Download Sales', 'In-Store Sales', 'Mail Sales']; 
    public pieChartData:number[] = [300, 500, 100]; 

    public randomizeType():void { 
     this.lineChartType = this.lineChartType === 'line' ? 'bar' : 'line'; 
     this.pieChartType = this.pieChartType === 'doughnut' ? 'pie' : 'doughnut'; 
    } 

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

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

HTML

<div *ngIf="data"> 
    <span>Type {{data.type}}</span> 
    <span>Name {{data.name}}</span> 



</div> 
<div class="col-md-6"> 

    <base-chart class="chart" 
       [data]="lineChartData" 
       [labels]="lineChartLabels" 
       [options]="lineChartOptions" 
       [chartType]="lineChartType" 
       (chartHover)="chartHovered($event)" 
       (chartClick)="chartClicked($event)"></base-chart> 
</div> 
<div class="col-md-6"> 
    <base-chart class="chart" 
       [data]="pieChartData" 
       [labels]="pieChartLabels" 
       [chartType]="pieChartType" 
       (chartHover)="chartHovered($event)" 
       (chartClick)="chartClicked($event)"></base-chart> 
</div> 
<div class="col-md-12 text-center" style="margin-top: 10px;"> 
    <button (click)="randomizeType()" style="display: inline-block">Toggle</button> 
</div> 

答えて

2

は、コンポーネントの注釈内で次を追加してください:

@Component({ 
    ... 
    styles: [` 
    .chart { 
     display: block; 
    }` 
    ], 
+0

はい。 IDEはセレクタ.chartを使用しなかったと警告しました。しかし、チャートは今はうまくいった。どうして? –

+0

ブラウザは未知のタグ 'base-chart'をレンダリングする方法を知らないので – yurzui

関連する問題