-
Notifications
You must be signed in to change notification settings - Fork 5
/
angualr-echarts.js
31 lines (31 loc) · 1.15 KB
/
angualr-echarts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Created by Administrator on 2014/10/28.
*/
angular.module('ngEcharts', [])
.factory('$echartsConfig', [function () {
return {}
}])
//.factory('$echartsInstance', [function () {
// var instance = {};
// instance.getById = function (id) {
// return instance[id];
// };
// return instance;
//}])
.directive('echarts', ['$echartsConfig', function ($echartsConfig) {
return {
link: function (scope, element, attrs) {
if (!scope.$echartsInstance)scope.$echartsInstance = {};
scope.$watch(attrs.echarts, function () {
var option = angular.extend($echartsConfig, scope.$eval(attrs.echarts));
if (option.id) {
scope.$echartsInstance[option.id] = echarts.init(element[0]);
scope.$echartsInstance[option.id].setOption(option);
} else {
scope.$echartsInstance = echarts.init(element[0]);
scope.$echartsInstance.setOption(option);
}
})
}
};
}]);