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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
| seteChart: function (data, idx) { let vm = this let map = new Map([ [2, { xKey: 'moneyBacktDate', yKey: 'refundAmt', tit: ['同期数', '本期数', '同比增长率', '环比增长率'], listNm: { a: 'hisSettleDataQueryResponsesForT', h: 'hisSettleDataQueryResponses', r: 'hisSettleDataQueryResponsesForH' } }], ]) let keys = map.get(idx) let xData = [] let yDataT = [] let yDataH = [] let yDataR = [] let tit = keys.tit let listNm = keys.listNm data[listNm.a].forEach((item, index) => { yDataT.push(item[keys.yKey]) }) data[listNm.h].forEach((item, index) => { xData.push(item[keys.xKey]) yDataH.push(item[keys.yKey]) })
data[listNm.r].forEach((item, index) => { yDataR.push(item[keys.yKey]) }) let yRateH = vm.getLv(yDataR) let yRateT = vm.getLv(yDataT, yDataH)
let option = ApiUtils.pureData(vm.optionTpl)
option.legend.data = tit option.xAxis.data = xData option.tooltip = { trigger: 'axis', axisPointer: { type: 'shadow' }, formatter: function (params) { let html=params[0].name+"<br>" for(let i=0;i<params.length;i++){ html+='<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:'+params[i].color+';"></span>' if(option.series[params[i].seriesIndex].valueType==="percent"){ html+=params[i].seriesName+": "+params[i].value.toFixed(2)+"%<br>" }else{ html+=params[i].seriesName+": "+params[i].value+"<br>" } } return html } }
let min = Math.min(yRateH[2], yRateT[2]) let max = Math.max(yRateH[1], yRateT[1]) option.xAxis.axisLabel.rotate = '0' option.yAxis[1] = { type: 'value', min: min, max: max, axisLabel: { show: true, interval: 'auto', formatter: '{value} %' }, splitLine: { show: false }, } option.series = [ { name: tit[0], type: 'bar', data: yDataT, barMaxWidth: 45, }, { name: tit[1], type: 'bar', barGap: 0, data: yDataH, barMaxWidth: 45, }, { name: tit[2], yAxisIndex: 1, data: yRateT[0], type: 'line', symbolSize: 0, lineStyle: { normal: { width: 0 不显示折线图 } }, valueType: "percent" }, { name: tit[3], yAxisIndex: 1, data: yRateH[0], type: 'line', symbolSize: 0, lineStyle: { normal: { } }, valueType: "percent" } ] } return option },
resize() { [1, 2].forEach(item => { this.chartMap.get(item).resize() }) },
initChart: function (option, idx) { let vm = this let chart = document.getElementById(`dom_chart${idx}`) chart.style.width = (window.innerWidth * .8) - 120 + "px" let myChart = echarts.init(chart) vm.chartMap.set(idx, myChart) myChart.clear() myChart.setOption(this[`option${idx}`], true) vm.resizeChart(idx) },
resizeChart: function (idx) { let chart = document.getElementById(`dom_chart${idx}`) tools.on(window, 'resize', () => { chart.style.width = (window.innerWidth * .8) - 120 + "px" this.chartMap.get(idx).resize() }) },
getLv: function (arr, arr2) { if (arr.length === 0) return [] let ar = [] let len = arr2 ? arr2.length : arr.length - 1 for (let i = 0; i < len; i++) { let arrX = arr2 ? arr2[i] : arr[i + 1] let v = 0 if (arr[i] * 1 === 0) { v = 0 } else { v = (arrX * 10000) / (arr[i] * 10000) - 1 } let k = v.toFixed(2) * 100 ar.push(k) }
let min = Math.min(...ar) let max = Math.max(...ar) return [ar, max, min] } }
|