溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

vue怎么實現(xiàn)echarts中的儀表盤

發(fā)布時間:2022-03-28 09:07:22 來源:億速云 閱讀:360 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要介紹“vue怎么實現(xiàn)echarts中的儀表盤”,在日常操作中,相信很多人在vue怎么實現(xiàn)echarts中的儀表盤問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”vue怎么實現(xiàn)echarts中的儀表盤”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習吧!

最終結(jié)果

vue怎么實現(xiàn)echarts中的儀表盤

一、安裝

1. 首先需要安裝echarts依賴包

npm install echarts -S

2. 或者使用國內(nèi)的淘寶鏡像:

npm install -g cnpm --registry=https://registry.npm.taobao.org

二、創(chuàng)建圖表

全局引入

main.js

// 引入echarts
import echarts from 'echarts'

Vue.prototype.$echarts = echarts

Hello.vue

<div id="myChart" :></div>
export default {
    data(){
      return {}
    }, 
     mounted(){
        this.myChart() //函數(shù)調(diào)用
     },
     methods:{
        myChart() {
        let columnar = this.$echarts.init(document.getElementById('myChart'));
        columnar.setOption({
          tooltip : {
            formatter: "{a} <br/>{c} "
          },
          toolbox: {
            show: true,
            feature: {
              restore: {show: true},
              saveAsImage: {show: true}
            }
          },
          series : [
           {
                    name: '空氣質(zhì)量:',
                    type: 'gauge',
                    z: 3,
                    min: 0,
                    max: 500,
                    splitNumber: 10,
                    radius: '60%',
                    axisLine: {
                        lineStyle: {
                            width: 10,
                            color: [[0.1, 'green'], [0.2, 'yellow'],[0.3, 'orange'],[0.4,'#db555e'],[0.5,'#ba3779'],[1.1,'#881326'] ]
                        }
                    },
                    axisTick: {
                        length: 15,
                        lineStyle: {
                            color: 'auto'
                        }
                    },
                    //刻度分割線樣式
                    splitLine: {
                        length: 20,
                        lineStyle: {
                            color: 'white'
                        }
                    },
                    //刻度數(shù)字樣式
                    axisLabel: {
                        fontWeight:'bold',
                        color: '#0085FF',
                    },
                    detail : {
                        //說明數(shù)字大小
                        formatter: function (value) {
                            return value;
                        },
                        offsetCenter:['0%','80%'],
                        fontWeight: 'bolder',
                        borderRadius: 3,
                        backgroundColor: '#0085FF',
                        fontSize:14,
                        width: 100,
                        color: 'white',
                        padding:[5,15,2,15]
                    },
                data:[1,2,3,4,5,6,7]
                },
            {
                    name: 'PM2.5:',
                    type: 'gauge',
                    center: ['20%', '55%'],
                    radius: '40%',
                    min:0,
                    max:350,
                    valu:55,
                    endAngle:45,
                    splitNumber:5,
                    axisLine: {
                        lineStyle: {
                            width: 8,
                            color: [[0.2, 'green'], [0.4, 'yellow'],[1.1,'orange'] ]
                        }
                    },
                

                    axisTick: {
                        length:12,
                        lineStyle: {
                            color: 'auto'
                        }
                    },
                    splitLine: {
                        length:20,
                        lineStyle: {
                            color: 'auto'
                        }
                    },
                    pointer: {
                        width:5,
                        color:'red'
                    },
                //刻度數(shù)字樣式
                    axisLabel: {
                        fontWeight:'bold',
                        color: '#0085FF',
                        fontSize:8,   //改變儀表盤內(nèi)刻度數(shù)字的大小
                        
                    },
                    detail: {
                        formatter: function (value) {
                            return value;
                        },
                        offsetCenter:['15%','75%'],
                        fontWeight: 'bolder',
                        borderRadius: 3,
                        backgroundColor: '#0085FF',
                        fontSize:14,
                        width: 100,
                        color: 'white',
                        padding:[5,15,2,15]
                    },
                    data:[1,2,3,4,5,6]
                },
           {
                    name: 'PM10:',
                    type: 'gauge',
                    //儀表盤位置
                    center: ['79%', '55%'],
                    //儀表盤半徑
                    radius: '40%',
                    min:0,
                    max:500,
                    startAngle:130,
                    splitNumber:5,
                    //儀表盤弧線寬度
                    axisLine: {
                        lineStyle: {
                            width: 8,
                            color: [[0.2, 'green'], [0.4, 'yellow'],[1, 'orange'] ]
                        }  
                        
                    },
                    //儀表盤小刻度樣式
                    axisTick: {
                        length:12,
                        lineStyle: {
                            color: 'auto'
                        }
                    },
                    //儀表盤大刻度樣式
                    splitLine: {
                        length:20,
                        lineStyle: {
                            color: 'auto'
                        }
                    },
                    //儀表盤指針樣式
                    pointer: {
                        width:5,//指針的寬度
                        length:"60%", //指針長度,按照半圓半徑的百分比
                        shadowColor : 'blue', //默認透明
                        shadowBlur: 5
                    },

                    //刻度數(shù)字樣式
                    axisLabel: {
                        fontWeight:'bold',
                        color: 'auto',
                        fontSize:8,   //改變儀表盤內(nèi)刻度數(shù)字的大小
                        
                    },
                    detail: {
                        //說明數(shù)字大小
                        formatter: function (value) {
                            return value;
                        },
                        //儀表盤下方文字說明
                        offsetCenter:['0%','80%'],
                        fontWeight: 'bolder',
                        borderRadius: 3,
                        backgroundColor: '#0085FF',
                        fontSize:14,
                        width: 100,
                        color: 'white',
                        padding:[5,15,2,15]
                    },
                data:[1,2,3,4]
                }
          ]
        })
      }
  }

到此,關(guān)于“vue怎么實現(xiàn)echarts中的儀表盤”的學(xué)習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習,快去試試吧!若想繼續(xù)學(xué)習更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI