Created
December 9, 2012 18:11
-
-
Save rsvalerio/4246337 to your computer and use it in GitHub Desktop.
angularjs googlechart pie directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* function MyCtrl { | |
* $scope.totalCaixas = [ | |
* ['Caixas', 'Qtd'], | |
* ['Conferidas', 11], | |
* ['Nao conferidas', 2] | |
* ]; | |
* } | |
* | |
* Index.html | |
* <script type="text/javascript" src="http://www.google.com/jsapi?ext.js"></script> | |
* <script type="text/javascript"> | |
* google.load('visualization', '1', {packages: ['corechart']}); | |
* </script> | |
* | |
* | |
* view: | |
* <pie data="totalCaixas" width="400"></pie> | |
* | |
* Pie chart directive | |
* | |
* | |
*/ | |
couchStatsApp.directive('pie', function() { | |
return { | |
restrict: 'E', | |
link: function($scope, $elm, $attr) { | |
var chartWidth = $attr.width; | |
console.log($attr.width); | |
// Create the data table. | |
var data = new google.visualization.arrayToDataTable( | |
$scope[$attr['data']]); | |
var chart = new google.visualization.PieChart($elm[0]); | |
chart.draw(data, { | |
'width': chartWidth | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment