Chartjs-Chart.js:4 Uncaught ReferenceError: require is not defined in ionic 2

0👍

To use chart.js in Ionic 2 RC0 just install the library and typings:

$ npm install chart.js --save
$ typings install chart.js --save

Include the library in the component’s header with

import 'chart.js/src/chart';
declare var Chart;

and use it e.g. for a line diagram with

let ctx = this.canvas.nativeElement
new Chart(ctx, {
  type: 'line',
  data: { your data },
  options:{ your options }
});

where canvas is the HTML element of the chart in the component’s template:

<canvas class="line-chart" #canvas></canvas>

0👍

OK! Instead of NPM module use.

bower install chart.js --save

This will download it to bower_components directives. then include it from there in your scripts

Leave a comment