$scope.generate = function() { var ctx = element[0].getContext("2d"); ctx.canvas.width = $scope.references.self.width; ctx.canvas.height = $scope.references.self.height; $scope.instance = eval('new Chart(ctx).' +attr.isType+ '($scope.data,$scope.options)'); }