Vue中使用Echarts儀表盤展示實(shí)時(shí)數(shù)據(jù)的實(shí)現(xiàn)
在vue中echarts儀表盤實(shí)時(shí)數(shù)據(jù)彩筆一枚,簡單記錄一下。業(yè)務(wù)場(chǎng)景:通過websocket實(shí)時(shí)推送數(shù)據(jù),將數(shù)據(jù)渲染到儀表盤中。
第一步:基于準(zhǔn)備好的dom,初始化echarts儀表盤實(shí)例。
第二步:我是通過父子組件傳值把數(shù)據(jù)接收過來,在data中定義upPressure參數(shù),并將接收來的devicePressure參數(shù)賦值給它,便于后面將值傳入到echarts中
父組件中 <div shadow='always'> <objEcharts :devicePressure='pressure'></objEcharts> </div>子組件中export default { props: { devicePressure: { type: String, require: true }, }, data() { return { upPressure: this.devicePressure, }; },
第三步:因?yàn)槭菍?shí)時(shí)數(shù)據(jù),就需要在watch中監(jiān)聽數(shù)據(jù)變化,實(shí)時(shí)更新。注:這里我只監(jiān)聽一個(gè)參數(shù)變化,沒有使用deep: true。
watch: { //監(jiān)聽devicePressure的數(shù)據(jù)變化。 devicePressure(newData, oldData) { //把更新后的數(shù)據(jù)newData,賦值給需要傳入echarts中的參數(shù)。 this.upPressure = newData; //一定要調(diào)用echarts實(shí)例,要不然echarts不實(shí)時(shí)展示。 this.drawLine(); }, },
第四步:數(shù)據(jù)處理完之后,就要把它展示到儀表盤中了,所以直接找到echarts中需要數(shù)據(jù)的地方就好了。介于儀表盤樣式,可結(jié)合官方文檔自定義。
export default { props: { devicePressure: { type: String, require: true }, }, data() { return { upPressure: this.devicePressure, }; }, mounted() { this.drawLine(); }, watch: { devicePressure(newData, oldData) { this.upPressure = newData; this.drawLine(); }, },methods: { drawLine() { // 基于準(zhǔn)備好的dom,初始化echarts實(shí)例 let visualOneChart = this.$echarts.init(document.getElementById('visualOneChart')); // 繪制圖表 visualOneChart.setOption({ tooltip: { formatter: '{a} <br/>{b} : {c}Pa', }, series: [ { name: '壓力值', type: 'gauge', clockwise: true, detail: { formatter: this.upPressure, textStyle: {fontSize: 14, }, }, data: [{ value: this.upPressure, name: '壓力值' }], radius: '90%', axisLabel: {// 刻度標(biāo)簽。 show: true, distance: -5, color: 'black',fontSize: 10,formatter: '{value}', }, axisLine: {// 儀表盤軸線(輪廓線)相關(guān)配置。 show: true,lineStyle: {// 儀表盤軸線樣式。opacity: 1, width: 15, shadowBlur: 10,}, }, pointer: { // 儀表盤指針。 show: true, length: '70%',width: 4, }, }, ], }); }, },}
到此這篇關(guān)于Vue中使用Echarts儀表盤展示實(shí)時(shí)數(shù)據(jù)的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Vue Echarts儀表盤 內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. React+umi+typeScript創(chuàng)建項(xiàng)目的過程2. ASP.NET Core 5.0中的Host.CreateDefaultBuilder執(zhí)行過程解析3. SharePoint Server 2019新特性介紹4. ASP中常用的22個(gè)FSO文件操作函數(shù)整理5. 三個(gè)不常見的 HTML5 實(shí)用新特性簡介6. ASP調(diào)用WebService轉(zhuǎn)化成JSON數(shù)據(jù),附j(luò)son.min.asp7. .Net core 的熱插拔機(jī)制的深入探索及卸載問題求救指南8. 無線標(biāo)記語言(WML)基礎(chǔ)之WMLScript 基礎(chǔ)第1/2頁9. 讀大數(shù)據(jù)量的XML文件的讀取問題10. 解決ASP中http狀態(tài)跳轉(zhuǎn)返回錯(cuò)誤頁的問題
