TL;DR
You patched the ng2-charts
package with that import after installing charts.js
and then you just used the ng2-charts
package as if you had used the script
tag in index.html
?
Yes thatâs correct.
And then when you import CHART_DIRECTIVES from chart.ts it will import that automatically
No my sample doesnât reflect that idea but I will update it and make it reflect the idea.
Donât like the idea but at least it works.
So itâs the start of Charts.js
or can we use it now? it seems like a fork of ng2-charts just for that.
I think i will fork ng2-charts
and add the chart.js
import instead of patching the library, it will work in the meantime.
This is even better if itâs fully developed. Uses the latest version of Chart.js (V2 BETA)
So thatâs why i didnât saw the file chart.js/Chart.min.js
anywhere, so you suggest i grab ng2-charts, fork, grab peer dependency on charts.js V2.beta2 and make it work?
Not sure if it would work like that. You might have to create the definitions/directives from scratch.
Checkout the documentation here for Chart.js v2: http://nnnick.github.io/Chart.js/docs-v2/
It looks pretty much the same as V1 but I am sure a lot has changed.
edit v2 available for download via the github repo https://github.com/nnnick/Chart.js
V2 docs has changed, but i have no time to mess with the code right now, later iâll see what has changed in my home.
We can collaborate on it in the future once Angular2, Ionic2 & Chart.js2 are getting more stable. Would be interesting.
Ok i think i will stick with c3 for now, iâll try to contribute later when i have time to spare.
I put a quick demo together for that conceptâŚ
You can clone repo here: https://github.com/ihadeed/ionic2-ng2charts
Ja, nailed it, using the Webpack ProvidePlugin we can use the ng2-charts in a cleaner way, care to try it out? i have tested but seems iâm not setting up the chart correctly and no time to debug:
var path = require('path');
var ProvidePlugin = require('webpack/lib/ProvidePlugin');
module.exports = {
entry: [
path.normalize('es6-shim/es6-shim.min'),
'reflect-metadata',
path.normalize('zone.js/dist/zone-microtask'),
path.resolve('app/app')
],
output: {
path: path.resolve('www/build/js'),
filename: 'app.bundle.js',
pathinfo: false // show module paths in the bundle, handy for debugging
},
module: {
loaders: [
{
test: /\.ts$/,
loader: 'awesome-typescript',
query: {
doTypeCheck: true,
resolveGlobs: false,
externals: ['typings/browser.d.ts']
},
include: path.resolve('app'),
exclude: /node_modules/
},
{
test: /\.js$/,
include: path.resolve('node_modules/angular2'),
loader: 'strip-sourcemap'
}
],
noParse: [
/es6-shim/,
/reflect-metadata/,
/zone\.js(\/|\\)dist(\/|\\)zone-microtask/
]
},
plugins: [
new ProvidePlugin({
Chart: 'chart.js/Chart.min.js',
})
],
resolve: {
root: ['app'],
alias: {
'angular2': path.resolve('node_modules/angular2')
},
extensions: ["", ".js", ".ts"]
}
};
I manage to delete the error but nothing renders, i think is a different error of the ng2-charts
lib.
Hey Carlos,
I will test it out soon once Iâm done with some work. Seems interesting to try out!
Youâve almost saved my day.
I used this https://github.com/mhartington/ionicv2-c3js.git
thx.
But i get new errors. One in particular:
ângAfterViewInit is not definedâ.
How in your script do you load this function?
I tried an
import {AfterViewInit} from âangular2/bundles/angular2â;
But no success
Nop, ngAfterViewInit
is a property of angular components, relate to: Directive and component change detection and lifecycle hooks
Go to that section and search for ngAfterViewInit
.
Ok but it doesnât explain the error.
In his script âmhartingtonâ has an:
"import {Page} from âionic-angularâ;â
My imports are all from âionic-framework/ionicâ or c3:
import {Page, NavController, NavParams} from âionic-framework/ionicâ;
import {Platform} from âionic-framework/ionicâ;
import * as c3 from âc3â;
And i get:
âError during instantiation ofâ my page and
"ngAfterViewInit is not definedâ.
Is it the âexport class ChartsPage implements AfterViewInitâ which doesnât really works ?
How do I have this ângAfterViewInitâ property available?
His example uses ionic-angular
because heâs using ionic framework 2.0.0-beta.2+ (+ means 2 or more), if you see the changelog the npm package was renamed in beta.2 to ionic-angular
, the c3
import is OK.
So hereâs some questions to be able to answer better:
- Did you run
npm i
on the project? - Are you using webpack or browserify?
- Whatâs the output of
ionic info
?
Side note: ngAfterViewInit
is just a function that angular 2 components will call whenever the view has been initialized, just like the constructor
getâs called each time you use the call, ngAfterViewInit
is called just after the constructor
and after the view is initialized, take note on the link of my previous post (Did you even looked at it), this method only apply to components, in ionic means it applies to Pages and Components, the ones that uses templates in html.