Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.
This repository was archived by the owner on Dec 11, 2020. It is now read-only.

如何运用echarts dispatchaction功能 #14

@shenmegui9

Description

@shenmegui9

看ng-echarts.js并没有封装dispatchaction功能,我修改了之后可以用,但每次跳index都会刷新chart使得浏览器自动关闭,而不是像官网的dispatch demo并没有刷新chart。
请问可以怎样改呢?

/**

  • Created by liekkas.zeng on 2015/1/7.
    */
    angular.module('ng-echarts',[])
    .directive('ngEcharts',[function(){
    return {
    link: function(scope,element,attrs,ctrl,$window){
    function refreshChart(){
    var theme = (scope.config && scope.config.theme)
    ? scope.config.theme : 'default';
    var chart = echarts.init(element[0],theme);
    var app = {};

                 if(scope.config && scope.config.dataLoaded === false){
                     chart.showLoading();
                 }
    
                 if(scope.config && scope.config.dataLoaded){
                     chart.setOption(scope.option);
                     chart.resize();
                     chart.hideLoading();
                 }
    
                 if(scope.config && scope.config.event){
                     if(angular.isArray(scope.config.event)){
                         angular.forEach(scope.config.event,function(value,key){
                             for(var e in value){
                                 chart.on(e,value[e]);
                             }
                         });
                     }
                 }
    

// chart.dispatchAction({
// type: 'downplay',
// seriesIndex: 0,
// dataIndex: scope.currentIndex;
// });

                if(angular.isDefined(scope.currentIndex)){
                	
                	chart.dispatchAction({
    			        type: 'highlight',
    			        seriesIndex: 0,
    			        dataIndex: scope.currentIndex
    			    });
    			    
                    chart.dispatchAction({
    			        type: 'showTip',
    			        seriesIndex: 0,
    			        dataIndex: scope.currentIndex
    			    });                        	
                }                                     
            };

            scope.$watch(
                function () { return scope.config; },
                function (value) {if (value) {refreshChart();                  
                }},
                true
            );


            scope.$watch(
                function () { return scope.option; },
                function (value) {if (value) {refreshChart();
               
                }},
                true
            );
            scope.$watch(
                    function () { return scope.currentIndex; },
                    function (value) {if (value) {refreshChart();
                   
                    }},
                    true
                );

// scope.$watch(
// function () { return scope.windowSize; },
// function (value) {
// console.log("directive watch window size");
// if (value) {refreshChart();
//
// }},
// true
// );

        },
        scope:{
            option:'=ecOption',
            config:'=ecConfig',
            currentIndex: '=ecCurrentIndex'
           // windowSize: '=ecWindowSize'
        },
        restrict:'EA'
    }
}]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions