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/> : {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. CSS hack用法案例詳解2. 利用promise及參數(shù)解構(gòu)封裝ajax請(qǐng)求的方法3. JSP數(shù)據(jù)交互實(shí)現(xiàn)過程解析4. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說明5. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向6. Ajax實(shí)現(xiàn)表格中信息不刷新頁面進(jìn)行更新數(shù)據(jù)7. PHP設(shè)計(jì)模式中工廠模式深入詳解8. 解決AJAX返回狀態(tài)200沒有調(diào)用success的問題9. .NET中l(wèi)ambda表達(dá)式合并問題及解決方法10. ThinkPHP5實(shí)現(xiàn)JWT Token認(rèn)證的過程(親測(cè)可用)
