Merge branch 'master' of http://113.200.75.45:82/monitor_v3/hg-monitor-web into master-V32-XuHaoJie
Showing
2 changed files
with
322 additions
and
0 deletions
1 | +<LineChart :optionData="optionData" v-if="optionData"></LineChart> |
1 | +export default { | ||
2 | + name: 'availabilityLine', | ||
3 | + template: '', | ||
4 | + props:['busId','kpiIds'], | ||
5 | + components: { | ||
6 | + 'LineChart': Vue.defineAsyncComponent( | ||
7 | + () => myImport('views/zjdaping/components/lineChart/index') | ||
8 | + ) | ||
9 | + }, | ||
10 | + data(){ | ||
11 | + return { | ||
12 | + domainName:sessionStorage.getItem('domainName'), | ||
13 | + apiUrl:'/api-web/sxview/getBusinessAvailability', | ||
14 | + // kpiIds:'KPIFE85BE59,KPI7A29BAC3,KPI5F8CCDA0,KPIE7A7E3E4,KPI97B835A4',//成功率,响应率,业务量,业务告警量,可用性 | ||
15 | + // busId:'7a9d2360e09f4ed8aaa8011ceb4178fd', | ||
16 | + // busId:'', | ||
17 | + performanceData:'', | ||
18 | + xAxisData:'', | ||
19 | + yAxisData:'', | ||
20 | + optionData:'', | ||
21 | + ySeriesCommon:[] | ||
22 | + } | ||
23 | + }, | ||
24 | + setup(props, {attrs, slots, emit}) { | ||
25 | + const {proxy} = Vue.getCurrentInstance(); | ||
26 | + const xAxisData=Vue.ref(); | ||
27 | + const yAxisData=Vue.ref([]); | ||
28 | + const legendData=Vue.ref([]); | ||
29 | + const ySeriesCommon=Vue.ref([]); | ||
30 | + | ||
31 | + // 半透明的颜色值 | ||
32 | + const colorArr1 = [ | ||
33 | + 'rgba(23,212,152, 0.8)', | ||
34 | + 'rgba(253,152,58, 0.8)', | ||
35 | + 'rgba(255,238,0, 0.8)', | ||
36 | + 'rgba(255,113,66, 0.8)', | ||
37 | + 'rgba(255,0,255, 0.8)', | ||
38 | + ] | ||
39 | + // 全透明的颜色值 | ||
40 | + const colorArr2 = [ | ||
41 | + 'rgba(23,212,152, 0)', | ||
42 | + 'rgba(253,152,58, 0)', | ||
43 | + 'rgba(255,238,0, 0)', | ||
44 | + 'rgba(255,113,66, 0)', | ||
45 | + 'rgba(255,0,255, 0)', | ||
46 | + ] | ||
47 | + // 挂载完 | ||
48 | + Vue.onMounted(() => { | ||
49 | + proxy.getData(); | ||
50 | + | ||
51 | + }) | ||
52 | + const getData=()=>{ | ||
53 | + let params = { | ||
54 | + kpiIds: props.kpiIds, | ||
55 | + busId: props.busId, | ||
56 | + startTime:'', | ||
57 | + endTime:'', | ||
58 | + access_token:localStorage.getItem('access_token') | ||
59 | + }; | ||
60 | + $.get(proxy.domainName +proxy.apiUrl+'?access_token='+localStorage.getItem('access_token'),params,function (res) { | ||
61 | + console.log("yewu") | ||
62 | + const data = res; | ||
63 | + let legendData=Vue.ref([]); | ||
64 | + let xAxisData=Vue.ref([]); | ||
65 | + let yAxisData=Vue.ref([]); | ||
66 | + let mapData={ | ||
67 | + legend:[ "成功率","响应率","业务量","业务告警量","可用性"], | ||
68 | + x:[ "10:00","10:15","10:30", "10:45","11:00","11:15","11:30","11:45","12:00","12:15","12:30","12:45", "13:00","13:15","13:30","13:45", | ||
69 | + "14:00","14:15","14:30", "14:45","15:00","15:15","15:30","15:45","16:00","16:15","16:30","16:45", "17:00","17:15","17:30","17:45", | ||
70 | + "18:00","18:15","18:30", "18:45","19:00","19:15","19:30","19:45","20:00","20:15","20:30","20:45", "21:00","21:15","21:30","21:45", | ||
71 | + "22:00","22:15","22:30", "22:45","23:00","23:15","23:30","23:45","00:00","00:15","00:30","00:45", "01:00","01:15","01:30","01:45", | ||
72 | + "02:00","02:15","02:30", "02:45","03:00","03:15","03:30","03:45","04:00","04:15","04:30","04:45", "05:00","05:15","05:30","05:45", | ||
73 | + "06:00","06:15","06:30", "06:45","07:00","07:15","07:30","07:45","08:00","08:15","08:30","08:45", "09:00","09:15","09:30","09:45", | ||
74 | + "10:00" | ||
75 | + ], | ||
76 | + y:[[ 0,0,0,0,0,0,0,0],[ 0,0,0,0,0,0,0,0],[ 0,0,0,0,0,0,0,0],[ 0,0,0,0,0,0,0,0],[ 0,0,0,0,0,0,0,0],[ 0,0,0,0,0,0,0,0],[ 0,0,0,0,0,0,0,0] | ||
77 | + ] | ||
78 | + } | ||
79 | + if (data ) { | ||
80 | + if(data.map){ | ||
81 | + let resData=data.map; | ||
82 | + if(!resData.x || resData.x.length==0){ | ||
83 | + resData=mapData; | ||
84 | + } | ||
85 | + xAxisData=resData.x; | ||
86 | + yAxisData=resData.y; | ||
87 | + legendData=resData.legend; | ||
88 | + | ||
89 | + }else{ | ||
90 | + xAxisData=mapData.x; | ||
91 | + yAxisData=mapData.y; | ||
92 | + legendData=mapData.legend; | ||
93 | + } | ||
94 | + proxy.legendData= legendData; | ||
95 | + proxy.xAxisData=xAxisData; | ||
96 | + proxy.yAxisData=yAxisData; | ||
97 | + proxy.optionInit(); | ||
98 | + | ||
99 | + } | ||
100 | + | ||
101 | + }) | ||
102 | + // proxy.optionInit(); | ||
103 | + | ||
104 | + } | ||
105 | + const optionInit=()=>{ | ||
106 | + | ||
107 | + let data3=proxy.yAxisData[0]; | ||
108 | + let data4=proxy.yAxisData[3]; | ||
109 | + let min2=proxy.calMin([data3,data4]); | ||
110 | + let max2=proxy.calMax([data3,data4]); | ||
111 | + let ySeriesCommon=[]; | ||
112 | + proxy.legendData.map((item,index)=>{ | ||
113 | + let i=0; | ||
114 | + if(index%2==0 ||index%3==0){ | ||
115 | + i=0; | ||
116 | + }else{ | ||
117 | + i=1; | ||
118 | + } | ||
119 | + let areaStyle=0; | ||
120 | + if(i==2){ | ||
121 | + areaStyle=1 | ||
122 | + } | ||
123 | + ySeriesCommon.push( | ||
124 | + { | ||
125 | + name:item, | ||
126 | + type: 'line', | ||
127 | + smooth:true, | ||
128 | + // stack: 'Total', | ||
129 | + show:false, | ||
130 | + data:proxy.yAxisData[index], | ||
131 | + yAxisIndex:i, | ||
132 | + showSymbol:false, | ||
133 | + itemStyle : { | ||
134 | + normal : { | ||
135 | + color:colorArr1[index],//tooltip里的小圆点颜色 | ||
136 | + lineStyle:{ | ||
137 | + color:colorArr1[index], | ||
138 | + width:1 | ||
139 | + } | ||
140 | + } | ||
141 | + }, | ||
142 | + areaStyle: { | ||
143 | + // color:'rgba(151,213,244,0.4)', | ||
144 | + normal:{ | ||
145 | + color:new echarts.graphic.LinearGradient(0, 0, 0, areaStyle, [{ //关键在这里, 设置面积渐变 | ||
146 | + offset: 0, | ||
147 | + color: colorArr1[index] //这里是我设置的渐变的颜色从线条颜色变为透明 | ||
148 | + }, { | ||
149 | + offset: 1, | ||
150 | + color: colorArr2[index] | ||
151 | + }]) | ||
152 | + } | ||
153 | + | ||
154 | + }, | ||
155 | + }, | ||
156 | + ) | ||
157 | + }) | ||
158 | + proxy.ySeriesCommon=ySeriesCommon; | ||
159 | + | ||
160 | + // let xAxisDataLength=proxy.ySeriesCommon[0].length; | ||
161 | + let xAxisData=[]; | ||
162 | + if(proxy.xAxisData){ | ||
163 | + proxy.xAxisData.map((item,index)=>{ | ||
164 | + if(index%20==0){ | ||
165 | + xAxisData.push(item) | ||
166 | + | ||
167 | + } | ||
168 | + }) | ||
169 | + | ||
170 | + } | ||
171 | + proxy.optionData = { | ||
172 | + title: { | ||
173 | + text: '' | ||
174 | + }, | ||
175 | + tooltip: { | ||
176 | + trigger: 'axis', | ||
177 | + backgroundColor:'rgba(50,50,50,0.7)', | ||
178 | + borderColor:"#333", | ||
179 | + formatter:function(params){ | ||
180 | + let str='<div>'+params[0].name+'</div>'; | ||
181 | + let unit='%'; | ||
182 | + for(let i=0;i<params.length;i++){ | ||
183 | + if(i==3){ | ||
184 | + unit=" 个" | ||
185 | + }else{ | ||
186 | + unit="%" | ||
187 | + } | ||
188 | + let dataVal=0; | ||
189 | + if(params[i].data && params[i].data!=undefined && params[i].data!='undefined') { | ||
190 | + dataVal=params[i].data | ||
191 | + } | ||
192 | + str+="<div style='display:flex;justify-content: space-between'><span>"+params[i].marker+params[i].seriesName+"</span><span style='margin-left:10px;'>"+dataVal+unit+"</span></div>" | ||
193 | + } | ||
194 | + return str | ||
195 | + }, | ||
196 | + textStyle:{ | ||
197 | + color:"#fff", | ||
198 | + align:'left' | ||
199 | + } | ||
200 | + | ||
201 | + }, | ||
202 | + legend: { | ||
203 | + data: proxy.legendData, | ||
204 | + itemHeight:0,//图例圆圈大小设置 | ||
205 | + y:'0px', | ||
206 | + textStyle: { | ||
207 | + color: '#ffffff', | ||
208 | + fontsize:"12px" | ||
209 | + } | ||
210 | + | ||
211 | + }, | ||
212 | + grid: { | ||
213 | + top:'10%', | ||
214 | + left: '3%', | ||
215 | + right: '8%', | ||
216 | + bottom: '20%', | ||
217 | + containLabel: true, | ||
218 | + }, | ||
219 | + xAxis: { | ||
220 | + type: 'category', | ||
221 | + boundaryGap: false, | ||
222 | + data: proxy.xAxisData, | ||
223 | + | ||
224 | + axisLine:{ | ||
225 | + show:false,//是否显示坐标线 | ||
226 | + }, | ||
227 | + axisTick: { | ||
228 | + show: false //是否显示坐标刻度 | ||
229 | + }, | ||
230 | + axisLabel:{ | ||
231 | + color:'#ffffff', | ||
232 | + }, | ||
233 | + | ||
234 | + }, | ||
235 | + yAxis:[ | ||
236 | + { | ||
237 | + | ||
238 | + type: 'value', | ||
239 | + axisLabel: { | ||
240 | + formatter: '{value} %'//以百分比显示 | ||
241 | + }, | ||
242 | + splitLine:{ | ||
243 | + lineStyle: { | ||
244 | + color:'#0a1b31' | ||
245 | + } | ||
246 | + }, | ||
247 | + // position:'right', | ||
248 | + min:0, | ||
249 | + max:100, | ||
250 | + splitNumber:10, | ||
251 | + interval:(100-0)/10 | ||
252 | + }, | ||
253 | + { | ||
254 | + name: '单位:个', | ||
255 | + type: 'value', | ||
256 | + axisLabel: { | ||
257 | + show: true, | ||
258 | + interval: 'right',//居中显示 | ||
259 | + }, | ||
260 | + splitLine:{ | ||
261 | + lineStyle: { | ||
262 | + color:'#0a1b31' | ||
263 | + } | ||
264 | + }, | ||
265 | + min:min2, | ||
266 | + max:max2, | ||
267 | + splitNumber:10, | ||
268 | + interval:(max2-min2)/10 | ||
269 | + }, | ||
270 | + ], | ||
271 | + series: proxy.ySeriesCommon, | ||
272 | + itemStyle:{ | ||
273 | + showSymbol:false | ||
274 | + } | ||
275 | + }; | ||
276 | + } | ||
277 | + //计算最大值 | ||
278 | + const calMax=(arr)=>{ | ||
279 | + let max=0; | ||
280 | + arr.forEach((el)=>{ | ||
281 | + el.forEach((el1)=>{ | ||
282 | + if(!(el1 === undefined || el1 === '')){ | ||
283 | + if(max<el1){ | ||
284 | + max=el1; | ||
285 | + } | ||
286 | + } | ||
287 | + }) | ||
288 | + }) | ||
289 | + let maxint=Math.ceil(max/9.5); | ||
290 | + let maxval=maxint * 10;//让显示的刻度是整数 | ||
291 | + return maxval; | ||
292 | + } | ||
293 | + //计算最小值 | ||
294 | + const calMin=(arr)=>{ | ||
295 | + let min=0; | ||
296 | + arr.forEach((el)=>{ | ||
297 | + el.forEach((el1)=>{ | ||
298 | + if(!(el1 === undefined || el1 === '')){ | ||
299 | + if(min>el1){ | ||
300 | + min=el1; | ||
301 | + } | ||
302 | + } | ||
303 | + }) | ||
304 | + }) | ||
305 | + let minint=Math.floor(min/10); | ||
306 | + let minval=minint * 10;//让显示的刻度是整数 | ||
307 | + return minval; | ||
308 | + } | ||
309 | + | ||
310 | + | ||
311 | + return{ | ||
312 | + calMax, | ||
313 | + calMin, | ||
314 | + getData, | ||
315 | + xAxisData, | ||
316 | + yAxisData, | ||
317 | + legendData, | ||
318 | + optionInit | ||
319 | + } | ||
320 | + } | ||
321 | +} |
-
Please register or login to post a comment