'use strict';
define([ 'workspace/workspace.module' ], function (workspaceModule) {
workspaceModule.directive('stackedEchart', function () { var echeartOption = function (me) { var axisData = [['0点', 0, 0, 0, 0, 0], ['1点', 0, 0, 0, 0, 0], ['2点', 0, 0, 0, 0, 0], ['3点', 0, 0, 0, 0, 0], ['4点', 0, 0, 0, 0, 0], ['5点', 0, 0, 0, 0, 0], ['6点', 0, 0, 0, 0, 0], ['7点', 0, 0, 0, 0, 0], ['8点', 0, 0, 0, 0, 0], ['9点', 0, 0, 0, 0, 0], ['10点', 0, 0, 0, 0, 0], ['11点', 0, 0, 0, 0, 0], ['12点', 0, 0, 0, 0, 0], ['13点', 0, 0, 0, 0, 0], ['14点', 0, 0, 0, 0, 0], ['15点', 0, 0, 0, 0, 0], ['16点', 0, 0, 0, 0, 0], ['17点', 0, 0, 0, 0, 0], ['18点', 0, 0, 0, 0, 0], ['19点', 0, 0, 0, 0, 0], ['20点', 0, 0, 0, 0, 0], ['21点', 0, 0, 0, 0, 0], ['22点', 0, 0, 0, 0, 0], ['23点', 0, 0, 0, 0, 0]];
var stackedOption = { title: { text: me.etext || '平台注册用户量数据统计', subtext: me.esubtext || '实时数据', x: 'left' },
color: ['#3398DB'], tooltip: { trigger: me.etrigger || 'axis', axisPointer: { type: 'shadow' } }, legend: { data: me.elegendata || ['注册量(人)'] }, toolbox: { show: true, feature: me.efeature || { mark: { show: false }, dataView: { show: false, readOnly: false }, magicType: { show: true, type: ['line', 'bar'] }, restore: { show: false } } }, grid: { left: '1%', right: '3%', bottom: '2%', containLabel: true }, xAxis: me.exAxis || [ { data: (me.exAxisData || axisData).map(function (item) { return item[0]; }),
type: me.exAxisType || 'category' } ], yAxis: me.eyAxis || [ { type: 'value', min: 0, minInterval: 1 } ],
series: me.eseries || [ { name: 'PC', type: 'bar', stack: '注册', barWidth: 40, data: (me.exAxisData || axisData ).map(function (item) { return item[1]; }) }, { name: '触屏', type: 'bar', stack: '注册', data: (me.exAxisData || axisData ).map(function (item) { return item[2]; }) }, { name: 'IOS', type: 'bar', stack: '注册', data: (me.exAxisData || axisData ).map(function (item) { return item[3]; }) }, { name: '微信', type: 'bar', stack: '注册', data: (me.exAxisData || axisData ).map(function (item) { return item[4]; }) },
{ name: '安卓', type: 'bar', stack: '注册', data: (me.exAxisData || axisData ).map(function (item) { return item[5]; }), markPoint: { data: [ {type: 'max', name: '最大值'}, {type: 'min', name: '最小值'} ] }, markLine: { data: [ {type: 'average', name: '平均值'} ] } } ] };
me.echarts.clear(); me.echarts.setOption(stackedOption); };
return { restrict: 'AE',
replace: false,
scope: { source: '=' }, template: '<div>柱状图</div>',
controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) { }], controllerAs: 'stackedEchartController',
compile: function ($scope, element, attr) { var stacked = document.getElementById('echarts-stacked'); var me = me || {}; me.echarts = echarts.init(stacked);
return function ($scope, element, attr) { $scope.$watch( function ($scope) { return $scope.source; }, function () { var data = $scope.source; if (data && angular.isArray(data)) { var self = me; self.exAxisData = data; echeartOption(self); } }, true);
$scope.resizeDom = function () { return { 'height': stacked.offsetHeight, 'width': stacked.offsetWidth }; }; $scope.$watch($scope.resizeDom, function () { me.echarts.resize(); }, true);
echeartOption(me); } } }; }); });
|