-
Notifications
You must be signed in to change notification settings - Fork 54
如何运用echarts dispatchaction功能 #14
Description
看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'
}
}]);