This seems a little ungraceful - perhaps create an internal counter before the return block in the directive definition, i.e.

<pre>
.directive('uiChart', function() {
  var id = 0;
  return {
    ...
    link: function (scope, elem, attrs) {
      ...
      var chartId = attrs.id;
      if (angular.isUndefined(chartId)) {
        chartId = id++;
      }
      ...
  };
});