const app = getApp(); import * as echarts from '../../../../ec-canvas/echarts' // 这个是自己实际的目录 Component({ data:{ Ec: { lazyLoad: true, }, }, lifetimes: { attached: function () { this.init() }, moved: function () { }, detached: function () { }, }, methods:{ init(){ var that = this; that.selectComponent('#chartConDom').init((canvas, width, height, dpr) => { const chart = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr }); var option = that.getOrderWarnOption(); chart.setOption(option); return chart; }); }, getOrderWarnOption(){ var list = [ {name:"已使用",data:[{name:"2022",value:35,},{name:"2021",value:30,},{name:"2020",value:20,},{name:"2019",value:30,}]}, {name:"未使用",data:[{name:"2022",value:50,},{name:"2021",value:30,},{name:"2020",value:30,},{name:"2019",value:30,}]}, {name:"不良率",data:[{name:"2022",value:10,},{name:"2021",value:5,},{name:"2020",value:10,},{name:"2019",value:10,}]}, ] var fontSize = 10 var fontColor = "#999999" return { color:["#2D59E6","#7FD1FF","#E1291C","#2D59E6"], title:{ text:"历年所有试剂的数据", show:0, textStyle:{ color:fontColor, fontSize:fontSize, }, left:'15%', top:0, }, grid: { top: '20%', left: '6%', right: '4%', bottom: '3%', containLabel: true }, tooltip: { trigger: 'axis', axisPointer: { type: 'cross', } }, legend:{ icon:"circle", right:'auto', top:0, itemWidth:fontSize*0.8, itemHeight:fontSize, textStyle:{ fontSize:fontSize, color:fontColor, }, data:list.map(item=>item.name) }, yAxis: [ { type: 'value', name:"", splitNumber:5, axisTick:{show:false,}, axisLabel:{ fontSize:fontSize, color:fontColor, }, nameTextStyle:{ fontSize:fontSize, color:fontColor, }, nameGap:5, }, { type: 'value', position: 'right', splitNumber:5, boundaryGap:[0,1], name:"%", axisTick:{show:false,}, splitLine:{show:false,}, axisLabel:{ fontSize:fontSize, color:fontColor, }, nameTextStyle:{ fontSize:fontSize, color:fontColor, }, nameGap:5, }, ], xAxis: { type: 'category', // boundaryGap: false, axisTick:{show:false,}, axisLabel:{ fontSize:fontSize, color:fontColor, }, data: list[0].data.map(item=>item.name) }, series:this.setOptItem(list), } }, setOptItem(list){ var data = [] var fontSize = 10 for(var i in list){ if(i==2){ data.push({ type: 'line', name:"%", silent:1, yAxisIndex: 1, barMaxWidth:fontSize*1.5, name:list[i].name, data:list[i].data }) }else{ data.push({ type: 'bar', stack: 'Total', name:"千万", silent:1, barMaxWidth:fontSize*1.5, name:list[i].name, data:list[i].data }) } } return data }, }, })