How to export angularjs-nvd3 diagram to file

I would like to use the nvd3 diagram library in my AngularJS application using angularjs-nvd3 directives Is there a way to export any given nvd3 diagram to any of the image file formats?

+7
angularjs
source share
1 answer

Please send sample code for detailed reference.

To write a chart to a file for use

  • Register the callback on-ready with the nvd3 directive. This callback receives 2 parameters as shown below.

$scope.callback = function(scope,element){ $scope.myChartScope = scope; } $scope.callback = function(scope,element){ $scope.myChartScope = scope; } This $scope.myChartScope must contain a link to your svg element, console.log it, to see its contents

  • The parameter object for the line chart has a dispatch object that has a renderEnd attribute that is called when your chart is fully drawn. In this renderEnd you can access $scope.myChartScope.svg and then do what you want with it.

    You can use a library, for example https://github.com/exupero/saveSvgAsPng , to save the SVG to an image file. Everything is done on the client side.

Hope this answers your question!

+1
source share

All Articles