     year: '='
   link: (scope, element, attributes) ->
     scope.$watch 'entity.autorizado', ->
-      [entity, year] = [scope.entity, scope.year]
-      if entity? and entity.autorizado? and year?
-        buildGraph(element[0], entity)
+      entity = scope.entity
+      if entity? and entity.autorizado?
+        buildOrUpdateGraph(chart, element[0], entity)
 ]
 

angular.module('InescApp').directive 'monthlyGraph', ['$filter', ($filter) ->
  buildGraph = (svgElement, entity) ->
     nv.addGraph () ->
         data = processData(entity)
         chart = nv.models.multiChart()
               .x((d,i) -> d.x)
               .color(['#E74C3C','#C0392b','#3498DB'])

         chart.yAxis1.showMaxMin(true)
             .tickFormat($filter('roundedCurrency'))

         updateGraph(chart, svgElement, entity)

  updateGraph = (chart, svgElement, entity) ->
    data = processData(entity)
    d3.select(svgElement)
        .datum(data)
      .transition().duration(500).call(chart)

  processData = (entity) ->
    autorizado = entity.autorizado
