Ionic + Angular Charts: Uncaught Error: Chart.js l

2019-06-28 08:41发布

问题:

I am trying to include charts into my Ionic application, but I get error. I have download the angular.js folder and chart.js folder into my lib folder and added the following lines to index.html:

<script src="lib/angular-chart.js/dist/angular-chart.js"></script>
<script src="lib/chart.js/dist/Chart.js"></script>
<script src="lib/angular-chart.js/dist/angular-chart.min.js"></script>
<script src="lib/chart.js/dist/Chart.min.js"></script>

I also added chart.js to my module: angular.module('myApp', ['ionic', 'chart.js']) but I still get the error: Uncaught Error: Chart.js library needs to included

What am I doing wrong, how can I use chart.js in my app?

回答1:

The fix was to put before angular-chart.js as Jossef Harush implied as a comment in my post. Also it is redundant to import both ”min” and normal js files



回答2:

include js in this order

<script src="lib/chart.js/dist/Chart.min.js"></script>

<script src="lib/angular-chart.js/dist/angular-chart.min.js"></script>