Skip to content

Instantly share code, notes, and snippets.

@rsvalerio
Created December 9, 2012 18:11
Show Gist options
  • Save rsvalerio/4246337 to your computer and use it in GitHub Desktop.
Save rsvalerio/4246337 to your computer and use it in GitHub Desktop.
angularjs googlechart pie directive
'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