(function() {
    'use strict';
    
    angular
        .module('app.widgets')
        .directive('vgFuncChart', vgFuncChart);

    function vgFuncChart() {
        var directive = {
            restrict: 'E',
            // FIXME: TODO: should be parameterizable
            template: '<div id="abcd"></div>',
            scope: {
                title: '@',
                // TODO: avoid categories, use ticks
                categories: '=',
                funcValues: '='
//                domain: '=',
//                values: '='
            },
            link: function(scope, element, attrs) {
                //var subDiv = element[0].childNodes[0];
                var chartId = 'abcd';
                var chart = new Highcharts.Chart({
                    chart: {
                        renderTo: /*scope.*/chartId
                    },
                    title: {
                        text: scope.title
                    },
                    xAxis: {
                        categories: scope.categories
                    },
                    series: scope.funcValues
                });
                scope.$watch('funcValues', function(newValue) {
                    //chart.series.push(newValue[0]);
                    //chart.series.push(newValue[1]);
                    //chart.redraw();
                    console.log('vgFuncChart updated');
                }, true);
            }
        };
        return directive;
    }
    
})();

@@ -1081,24 +1081,10 @@
 es: 
-scope.funcValues
+%5B%5D
 %0A   
@@ -1188,36 +1188,43 @@
     
-//chart.series.push(
+deleteMissingSeries(chart, 
 newValue
 %5B0%5D)
@@ -1219,19 +1219,16 @@
 newValue
-%5B0%5D
 );%0A     
@@ -1246,36 +1246,36 @@
     
-//chart.series.push(
+addNewSeries(chart, 
 newValue
 %5B1%5D)
@@ -1274,11 +1274,8 @@
 alue
-%5B1%5D
 );%0A 
@@ -1297,23 +1297,44 @@
     
-//chart.redraw(
+updateExistingSeries(chart, newValue
 );%0A 
@@ -1476,14 +1476,1116 @@
  %7D%0A    %0A
+    function deleteMissingSeries(chart, newSeriesList) %7B%0A        chart.series.forEach(function(currentOrig) %7B%0A            var newSeries = newSeriesList.find(function(currentNew) %7B return currentOrig.name === currentNew.name %7D);%0A            if (newSeries === undefined) %7B%0A                currentOrig.remove();%0A            %7D%0A        %7D);%0A    %7D%0A    %0A    function addNewSeries(chart, newSeriesList) %7B%0A        newSeriesList.forEach(function(currentNew) %7B%0A            var existingSeries = chart.series.find(function(currentOrig) %7B return currentOrig.name === currentNew.name %7D);%0A            if (existingSeries === undefined) %7B%0A                chart.addSeries(currentNew);%0A            %7D%0A        %7D);%0A    %7D%0A    %0A    function updateExistingSeries(chart, newSeriesList) %7B%0A        chart.series.forEach(function(currentOrig) %7B%0A            var newSeries = newSeriesList.find(function(currentNew) %7B return currentOrig.name === currentNew.name %7D);%0A            if (newSeries === undefined) %7B%0A                throw 'Series not found';%0A            %7D%0A            currentOrig.setData(newSeries.data);%0A        %7D);%0A    %7D%0A    %0A
 %7D)();%0A

Fix chart update