LineChart_wev8.js 3.7 KB
define("LineChart_html",function(){return'<div id="NMEC_${id}" class="wev-comp-${compType}">\t<div class="wev-chart-container">\t\t{@if title}\t\t<div class="wev-chart-title">${title}</div>\t\t{@/if}\t\t$${loading.content}\t\t<div class="wev-chart" style="${style}"></div>\t\t<div class="wev-error" style="display:none;"></div>\t</div></div>'}),define(["mUtil","Component","wev-loading","chartHelper"],function(u,e,a,m){return e.init(function(t){var o,n,r={};e.super(this,t),this.type="LineChart",this.tpl=this.type+"_html",this.css="chart_css",this.components={loading:new a({delay:300,animation:1})};var d=this.viewModel={data:[],height:300,title:{show:!1,text:"",subtext:"",x:"center",y:0},grid:{},legend:{show:!0,bottom:0,textStyle:{color:"#333"}},axisLabel:{interval:"auto",rotate:0,fontSize:12},isShowMarkLine:!1,isShowLabel:!1,isShowArea:!1,color:"#c23531,#2f4554,#61a0a8,#d48265,#91c7ae,#749f83,#ca8622,#bda29a,#6e7074,#546570,#c4ccd3",labelFormat:"",advancedSearch:{},standalone:!0};this.beforeMount=function(){var t=u.toPixel(d.height||300,"height");if(d.width&&(t+=u.toPixel(d.width,"width")),d.style=t,u.isString(d.click)&&""!=d.click){var a=d.click;d.click=function(t){var e=a.replace(/\{_chart_name}/g,t.name).replace(/\{_chart_seriesName}/g,t.seriesName).replace(/\{_chart_value}/g,t.value);$u(e)}}d.title=d.title.text||"";var e=d.grid;e.right=e.right||(d.isShowMarkLine?30:20),e.top=d.isShowLabel?30:15,e.left=e.left||10,e.bottom=d.legend.show?35:10,e.containLabel=!0,d.grid=e},this.mounted=function(){o=this.$el.find(".wev-error"),n=this.$el.find(".wev-chart"),this.refresh()},this.refresh=function(){var t=this.components.loading;t.setRefs(this.$comp,"wev-refreshing"),t.show();var e=t.hide.bind(t);d.standalone&&u.isArray(d.data)?r.buildChart(d.data,e):r.loadData(e)},this.cacheSearchLast=function(t){d.searchLast=t},r.loadData=function(e){var a=(new Date).valueOf(),i=this,t=d.data;i.timestamp=a,d.standalone||(t=u.getActionUrl(i.type,{action:"getDatas",mec_id:d.id},i.pageid)),t&&u.getJSON(t,{},function(t){a==i.timestamp&&(r.buildChart(t.data,e),o.html("").hide(),d.advancedSearch.enable&&(d.toolbox={showTitle:!1,itemSize:28,right:d.grid.right||20,top:d.grid.top||20,feature:{myTool:{show:!0,icon:"image:///mobilemode/mobile/images/plugin/filter.png",onclick:function(){require(["mService"],function(t){t.show("customsearch",{id:i.id,pageid:i.pageid,searchLast:d.searchLast||{},conditions:d.advancedSearch.asFields,title:d.title||""})})}}}}))},function(t){o.html(t).show(),n.hide(),u.isFunction(e)&&e.call(this)})},r.buildChart=function(n,r){var h=$(".wev-chart",this.$el);require(["echarts"],function(t){var e=t.init(h[0]),l=[],s=[],c=[];n.forEach(function(n,r){Object.keys(n).forEach(function(t,e){var a=n[t];if(!e)return s.push(a);var i=c[e-1]||{},o=i.data||[];i.data=o,c[e-1]=i,0===r&&(i.name=t,l.push(t)),o.push(a)})});var a=c.map(function(t){var e={type:"line",name:t.name,data:t.data};return d.isShowMarkLine&&(e.markLine={data:[{type:"average",name:"平均值"}],itemStyle:{normal:{label:{show:!0,formatter:function(t){return m.formatNumber(t.value,d.labelFormat)}}}}}),d.isShowLabel&&(e.label={normal:{show:!0,position:"top",formatter:function(t){return m.formatNumber(t.value,d.labelFormat)}}}),d.isShowArea&&(e.areaStyle={normal:{}}),e}),i=d.legend;i.data=l,i.bottom=5;var o={tooltip:{trigger:"axis",confine:!0,position:function(t,e,a,i,o){a.style.transform="translateZ(0)"}},grid:d.grid,legend:i,calculable:!0,xAxis:{type:"category",boundaryGap:!1,data:s,axisLabel:d.axisLabel},yAxis:{type:"value"},series:a,toolbox:d.toolbox};d.color&&(o.color=d.color.split(",")),e.setOption(o),u.isFunction(d.click)&&e.on("click",function(t){d.click.call(this,t)}),u.isFunction(r)&&r.call(this)})},r.loadData=r.loadData.bind(this),r.buildChart=r.buildChart.bind(this)})});