Vue中使用Echarts儀表盤展示實時數(shù)據(jù)的實現(xiàn)
在vue中echarts儀表盤實時數(shù)據(jù)
彩筆一枚,簡單記錄一下。
業(yè)務場景:通過websocket實時推送數(shù)據(jù),將數(shù)據(jù)渲染到儀表盤中。
第一步:
基于準備好的dom,初始化echarts儀表盤實例。
第二步:
我是通過父子組件傳值把數(shù)據(jù)接收過來,在data中定義upPressure參數(shù),并將接收來的devicePressure參數(shù)賦值給它,便于后面將值傳入到echarts中
父組件中
<div class="chart" shadow="always">
<objEcharts :devicePressure="pressure"></objEcharts>
</div>
子組件中
export default {
props: {
devicePressure: { type: String, require: true },
},
data() {
return {
upPressure: this.devicePressure,
};
},
第三步:
因為是實時數(shù)據(jù),就需要在watch中監(jiān)聽數(shù)據(jù)變化,實時更新。
注:這里我只監(jiān)聽一個參數(shù)變化,沒有使用deep: true。
watch: {
//監(jiān)聽devicePressure的數(shù)據(jù)變化。
devicePressure(newData, oldData) {
//把更新后的數(shù)據(jù)newData,賦值給需要傳入echarts中的參數(shù)。
this.upPressure = newData;
//一定要調(diào)用echarts實例,要不然echarts不實時展示。
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() {
// 基于準備好的dom,初始化echarts實例
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: {// 刻度標簽。
show: true,
distance: -5,
color: "black",
fontSize: 10,
formatter: "{value}",
},
axisLine: {// 儀表盤軸線(輪廓線)相關配置。
show: true,
lineStyle: {// 儀表盤軸線樣式。
opacity: 1,
width: 15,
shadowBlur: 10,
},
},
pointer: { // 儀表盤指針。
show: true,
length: "70%",
width: 4,
},
},
],
});
},
},
}

到此這篇關于Vue中使用Echarts儀表盤展示實時數(shù)據(jù)的實現(xiàn)的文章就介紹到這了,更多相關Vue Echarts儀表盤 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
使用Vue3和Plotly.js繪制動態(tài)3D圖表的示例代碼
在數(shù)據(jù)可視化應用中,需要將數(shù)據(jù)動態(tài)加載到圖表中并進行實時更新,本文將展示如何使用Plotly.js和Vue.js實現(xiàn)這一功能,從加載外部數(shù)據(jù)到創(chuàng)建交互式圖表,文中有相關的代碼示例供大家參考,需要的朋友可以參考下2024-06-06
淺談webpack SplitChunksPlugin實用指南
這篇文章主要介紹了淺談webpack SplitChunksPlugin實用指南,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09
vue-preview動態(tài)獲取圖片寬高并增加旋轉(zhuǎn)功能的實現(xiàn)
這篇文章主要介紹了vue-preview動態(tài)獲取圖片寬高并增加旋轉(zhuǎn)功能的實現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07
vue與bootstrap實現(xiàn)時間選擇器的示例代碼
本篇文章主要介紹了vue與bootstrap實現(xiàn)時間選擇器的示例代碼,非常具有實用價值,需要的朋友可以參考下2017-08-08
Ant Design Upload 文件上傳功能的實現(xiàn)
這篇文章主要介紹了Ant Design Upload 文件上傳功能的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04

