hi, could you please provide some code with ionic2 and nvd3?
cause I have no chart display, importing nvd3 from typings is ok, but my chart remains unshowed / undefined…
I was able to successfully implement ng2-nvD3 into my app. Most of the steps mentioned in ng2-nvd3 github site will work except some additional steps to required to get things working. You can look at original sample by the author at plunkr - http://plnkr.co/edit/T4i7Zh?p=preview. I have explained the steps I followed below.
After you create a default ionic2 project (I am using RC0), go ahead and install ng2-nvd3 using npm.
Add the the three script files in index .html - see the plunkr url and see how index.html is coded. What I noticed in my ionic2 project is, if i made these changes in the src folder - index.html, those changes were not copied to the index.html of build folder. I made changes in both the places just to be consistent. Changes to index.html of build folder is what is finally used.
Include nvd3 in the app.modules.ts using import { nvD3 } from ‘…/…/node_modules/ng2-nvd3/lib/ng2-nvd3’;
Add an entry for the nvD3 in the declarations section of the same file. Do not add any entry into imports section.
Then add the regular code in the html template file where you want to show the chart.
In the corresponding ts file add code as per the plunkr code. However, do not add the directive tag in the @Component decorator section.
Now the most important step - you need to navigate to nvd3 source code folder under node-modules. Open ng2-nvd3.ts and change the code that looks like ngOnChanges(){
this.updateWithOptions(this.options);
}
The error you get is because d3 is not available inside. However, tickFormat is being used for just formatting the output so a workaround is to use the basic javascript function like toFixed. I replaced d3.format(’.02f’) to ‘toFixed’ function. The overall function looks like:
tickFormat: function(d){
return d.toFixed(2);
}
and works as intended. However it is not a replacement function for the format function provided by d3. But I guess you can use some other formatter to get the effect you want. For example, if you returned just a plain string ‘hello’ instead of d.toFoxed(2), the graph would show ‘hello’ at each coordinate.
Hi,
By doing above changes also it is working for ionic serve.
But when i do ‘ionic build android’ it is throwing error:
[17:16:58] Error: Unexpected value ‘nvD3’ declared by the module ‘AppModule’
[17:16:58] ngc failed
[17:16:58] ionic-app-script task: “build”
[17:16:58] Error: Error
npm ERR! Windows_NT 6.1.7601
npm ERR! argv “C:\Program Files\nodejs\node.exe” “C:\Users\gayathri.b\AppD
ata\Roaming\npm\node_modules\npm\bin\npm-cli.js” “run” “ionic:build” "–"
npm ERR! node v6.9.1
npm ERR! npm v4.0.5
npm ERR! code ELIFECYCLE
npm ERR! ionic-hello-world@ ionic:build: ionic-app-scripts build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ionic-hello-world@ ionic:build script ‘ionic-app-scripts
build’.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ionic-hello-world pac
kage,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ionic-app-scripts build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs ionic-hello-world
npm ERR! Or if that isn’t available, you can get their info via:
npm ERR! npm owner ls ionic-hello-world
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! D:\Gayathri\workspace\MobileHtml\npm-debug.log
This is because, nvd3 is not included in the index.html. It should be included just below the cordova.js include, as per the plunkr url, I mentioned in my post: http://plnkr.co/edit/T4i7Zh?p=preview