AngularJS Nvd3图表-在每个状态变化时调用回调

时间:2018-07-04 09:01:25

标签: angularjs charts angular-nvd3

我有一个图,该图可以具有一组数据或多组数据。我需要检查每个stateChange并触发回调(他会在每次更改时执行我需要执行的操作)。

这是我的图表:

 scope.options = {
            chart: {
                type: 'lineChart',
                height: 450,
                margin : {
                    top: 20,
                    right: 20,
                    bottom: 40,
                    left: 55
                },
                useInteractiveGuideline: false,
                dispatch: {
                    stateChange: function(){ console.log("stateChange"); },
                    changeState: function(){ console.log("changeState"); },
                    tooltipShow: function(){ console.log("tooltipShow"); },
                    tooltipHide: function(){ console.log("tooltipHide"); },

                },
                xAxis: {
                    axisLabel: 'Temperature (Celcius)'
                },
                yAxis: {
                    axisLabel: 'Fluorescence',
                    tickFormat: function(d){
                        return d3.format('0f')(d);
                    },
                    axisLabelDistance: -10
                },

                callback: function(chart){
                    console.log("!!! lineChart callback !!!");
                    // If there is a tm point we show it
                    if (data.length === 1 && angular.isObject(tmPoints[data[0].key])){
                        console.log("SHOW TM");
                        data[0].values.forEach(function(element){
                           if (parseInt(element.x) === parseInt(tmPoints[data[0].key].tm)){
                               // Recuperer l'objet point et non ses valeurs
                                highlightPoint(chart, {'point' : element}, 10, true);
                           }
                        });
                    }
                    console.log(data.length);

                    if (data.length === 1) {
                        chart.lines.dispatch.on("elementClick", function(e) {
                            // Faire ça uniquement si il y a UN graph
                            if (clickedPoints.length >= 2){
                                // Remove the first point of the array
                                var pointToDelete = clickedPoints.shift(0,1);
                                // And remove his highlight
                                removeHighlightPoint(pointToDelete, pointToDelete.element.attributes[1].nodeValue);
                            }
                            clickedPoints.push(e);
                            highlightPoint(chart, e, 7, false);
                        });
                    }



                },
            },
            title: {
                enable: true,
                text: 'Title for Line Chart'
            },


        };

当只显示一组数据时,我需要执行操作,如果有条件,但在开始时仅调用一次回调,如何在每个stateChange上调用?

我还需要在更改选项时调用回调,当前是在更改scope.options时,没有任何事件(stateChange)被触发,并且回调也未触发。

有人知道吗?

0 个答案:

没有答案