2017-05-03 5 views
1

私はES6を使用して角度jでカスタム棒グラフ指令を書き込もうとしています。私は、c3ライブラリをインストールしました。私はギャルプを実行すると、私はエラーを取得している "c3"は定義されていない - undefです。あなたが直接、それが「友好の角度」ではありませんc3はインストールした場合エラー "c3"が定義されていないno-undef

export class MyDirective {  
constructor($interval) { 
    'ngInject'; 
    this.template = '<div id=chart></div>'; 
    this.restrict = 'E'; 
    this.scope = {} 
    this.$interval = $interval; 
} 

compile(tElement) { 
    tElement.css('position', 'absolute'); 
} 

link(scope, element) { 
    this.$interval(() => this.chart(), 1000); 
} 

chart() { 
    c3.generate({ 
     bindto: '#chart', 
     data:{ 
      columns: [ 
       ['data1', 30, 200, 100, 400, 150, 250], 
       ['data2', 130, 100, 140, 200, 150, 50] 
      ], 
      type: 'bar' 
     }, 
     bar: { 
      width: { 
       ratio: 0.5 // this makes bar width 50% of length between ticks 
      } 
      // or 
      //width: 100 // this makes bar width 100px 
     }  
    });   
} 
} 
+0

です。bower installは適切なファイルをプロジェクトフォルダにのみダウンロードしますが、stiあなたのindex.htmlにスクリプトとcssファイルを含める必要があります。あなたのプロジェクト環境に応じて、これを行うgulpタスクを手助けするかもしれません... – simonberry

+0

gulpタスクにc3.jsとそれに依存するd3.jsファイルが含まれています。 – Sai

答えて

0

- 以下は、私のコードです。私はes2015に私のプロジェクトでC3を使用して(とバベルは蒸散)、私はそれをインストールするにはc3-angular

を使用することを選択:

bower install c3-angular --save 

や依存としてインポートする:

import 'c3-angular'; 
let barChartModule = angular.module('barChart', ['gridshore.c3js.chart']); 

これを行うと、ビューでチャートを定義できます。これは、examples here

+0

"c3"を追加してエラーを修正しました。.eslintrcファイル内の "globals":{"c3":true}にtrueが追加されました。 – Sai

関連する問題