google/chartjs.dart

TypeError: Cannot read property 'Chart' of undefined

Closed this issue · 6 comments

I am trying to use chartjs.dart in my project. However, getting the error: TypeError: Cannot read property 'Chart' of undefined. Would greatly appreciate any thoughts on how to resolve this. The example does work when I download it and run it. Just not in my project.

My dart version is: Dart VM version: 2.1.1-dev.3.2 (Thu Jan 24 11:50:07 2019 +0100) on "macos_x64" and my pubspec.yaml is:

name: my_proj
version: 0.0.1

environment:
sdk: '>=2.0.0 <3.0.0'

dependencies:
angular: ^5.2.0
angular_components: ^0.11.0
angular_forms: ^2.1.1
angular_router: ^2.0.0-alpha+21
#quiver: ^0.28.0
js: ^0.6.0
bootstrap_sass: any
intl: ^0.15.7
chartjs: ^0.5.0
analyzer: ^0.34.0
pam_shared_libs:
path: ../pam_shared_libs

dev_dependencies:
angular_test: ^2.0.0
build_runner: ^1.2.3
build_test: ^0.10.4
build_web_compilers: ^1.1.0
#intl_translation: ^0.17.2
#test: ^0.12.30
js: ^0.6.1+1
sass_builder: ^2.1.2
#angular_analyzer_plugin: ^0.0.17+5

analyzer:
strong-mode: true
transformers:

  • sass_builder

  • angular:
    entry_points:
    - web/main.dart

  • test/pub_serve:
    $include: test/**_test.dart

Thank you! Simple fix. Now to figure out the error when running the example within my project.

dart_sdk.js:99834 EXCEPTION: NoSuchMethodError: invalid member on null: 'length'
STACKTRACE:
https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.js 9853:20 acquireContext
https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.js 3795:27 construct
https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.js 6340:8 new Chart

THanks for the suggestion! It's before and still no luck.

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.js"></script>
<script defer src="main.dart.js"></script>

Got it! Of course I was trying to draw the chart when my div I wanted to draw it in wasn't on the page yet. Thank you great library!

Got it! Of course I was trying to draw the chart when my div I wanted to draw it in wasn't on the page yet. Thank you great library!

How is it possible in AngularDart to check if page is loaded and call then to insert the char?
I tried it with lifecycle hooks but no success.