Vue使用echarts定制特殊的儀表盤
本文實(shí)例為大家分享了Vue使用echarts定制特殊儀表盤的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)的效果:(初始化以及瀏覽器resize的時(shí)候數(shù)字和弧形條均為遞增動(dòng)畫)

HTML部分:
<!-- 為ECharts準(zhǔn)備一個(gè)具備大?。▽捀撸┑腄om --> <div class="main-echarts-contianer" ? ? ?ref="main"> </div>
CSS部分:
.main-echarts-contianer {
? width: 480px;
? height: 320px;
? display: flex;
? align-items: center;
? justify-content: center;
}JS部分:
drawClockChart () {
? // 指定圖表的配置項(xiàng)和數(shù)據(jù)
? let option = {
? ? 'series': [
? ? ? {
? ? ? ? 'name': '個(gè)人指標(biāo)',
? ? ? ? 'type': 'gauge',
? ? ? ? 'radius': '65%',
? ? ? ? 'startAngle': '240',
? ? ? ? 'endAngle': '-60',
? ? ? ? // 圖表的刻度分隔段數(shù)
? ? ? ? 'splitNumber': 5,
? ? ? ? // 圖表的軸線相關(guān)
? ? ? ? 'axisLine': {
? ? ? ? ? 'show': true,
? ? ? ? ? 'lineStyle': {
? ? ? ? ? ? 'color': [
? ? ? ? ? ? ? [
? ? ? ? ? ? ? ? 0.9,
? ? ? ? ? ? ? ? new this.$echarts.graphic.LinearGradient(0, 0, 1, 0, [{
? ? ? ? ? ? ? ? ? offset: 0,
? ? ? ? ? ? ? ? ? color: '#FFD900'
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? offset: 1,
? ? ? ? ? ? ? ? ? color: '#FF8000'
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ])
? ? ? ? ? ? ? ],
? ? ? ? ? ? ? [1, '#56606E']
? ? ? ? ? ? ],
? ? ? ? ? ? 'width': 15
? ? ? ? ? }
? ? ? ? },
? ? ? ? // 圖表的刻度及樣式
? ? ? ? 'axisTick': {
? ? ? ? ? 'lineStyle': {
? ? ? ? ? ? 'color': '#0F1318',
? ? ? ? ? ? 'width': 2
? ? ? ? ? },
? ? ? ? ? 'length': 15,
? ? ? ? ? 'splitNumber': 1
? ? ? ? },
? ? ? ? // 圖表的刻度標(biāo)簽(20、40、60等等)
? ? ? ? 'axisLabel': {
? ? ? ? ? 'distance': -8,
? ? ? ? ? 'textStyle': {
? ? ? ? ? ? 'color': '#9E9E9E'
? ? ? ? ? }
? ? ? ? },
? ? ? ? // 圖表的分割線
? ? ? ? 'splitLine': {
? ? ? ? ? 'show': false
? ? ? ? },
? ? ? ? // 圖表的指針
? ? ? ? 'pointer': {
? ? ? ? ? 'show': false
? ? ? ? },
? ? ? ? // 圖表的數(shù)據(jù)詳情
? ? ? ? 'detail': {
? ? ? ? ? 'formatter': function (params) {
? ? ? ? ? ? return '{title|' + '總體得分}' + '\n' + '{score|' + params + '}'
? ? ? ? ? },
? ? ? ? ? 'offsetCenter': [0, 0],
? ? ? ? ? 'rich': {
? ? ? ? ? ? 'title': {
? ? ? ? ? ? ? 'fontSize': 12,
? ? ? ? ? ? ? 'color': '#9E9E9E',
? ? ? ? ? ? ? 'lineHeight': 30
? ? ? ? ? ? },
? ? ? ? ? ? 'score': {
? ? ? ? ? ? ? 'fontSize': 27,
? ? ? ? ? ? ? 'color': '#fff'
? ? ? ? ? ? }
? ? ? ? ? }
? ? ? ? },
? ? ? ? // 圖表的標(biāo)題
? ? ? ? 'title': {
? ? ? ? ? 'offsetCenter': [0, '90%'],
? ? ? ? ? 'color': '#fff',
? ? ? ? ? 'fontSize': 14
? ? ? ? },
? ? ? ? 'data': [{
? ? ? ? ? 'name': '完成',
? ? ? ? ? 'value': 31
? ? ? ? }]
? ? ? },
? ? ? {
? ? ? ? 'name': '外層線',
? ? ? ? 'type': 'gauge',
? ? ? ? 'radius': '72%',
? ? ? ? 'startAngle': '240',
? ? ? ? 'endAngle': '-60',
? ? ? ? 'center': ['50%', '50%'],
? ? ? ? 'axisLine': {
? ? ? ? ? 'lineStyle': {
? ? ? ? ? ? 'width': 1,
? ? ? ? ? ? 'color': [[1, '#56606E']]
? ? ? ? ? }
? ? ? ? },
? ? ? ? 'splitLine': {
? ? ? ? ? 'length': -6,
? ? ? ? ? 'lineStyle': {
? ? ? ? ? ? 'opacity': 0
? ? ? ? ? }
? ? ? ? },
? ? ? ? 'axisLabel': {
? ? ? ? ? 'show': false
? ? ? ? },
? ? ? ? 'axisTick': {
? ? ? ? ? 'splitNumber': 1,
? ? ? ? ? 'lineStyle': {
? ? ? ? ? ? 'opacity': 0
? ? ? ? ? }
? ? ? ? },
? ? ? ? 'detail': {
? ? ? ? ? 'show': false
? ? ? ? },
? ? ? ? 'pointer': {
? ? ? ? ? 'show': false
? ? ? ? }
? ? ? }
? ? ]
? }
? let tempVal = 0
? clearInterval(this.clockChartTimer)
? this.clockChartTimer = setInterval(() => {
? ? if (tempVal > this.myIvstrAbility) {
? ? ? clearInterval(this.clockChartTimer)
? ? ? // 最后轉(zhuǎn)到最終數(shù)據(jù)的地方
? ? ? option.series[0].data[0].value = this.myIvstrAbility
? ? ? option.series[0].axisLine.lineStyle.color[0][0] = this.myIvstrAbility / 100
? ? ? // 使用剛指定的配置項(xiàng)和數(shù)據(jù)顯示圖表
? ? ? this.myChart.setOption(option)
? ? ? // 初始化渲染完成
? ? ? this.renderCompleted = true
? ? ? return
? ? }
? ? option.series[0].data[0].value = tempVal
? ? option.series[0].axisLine.lineStyle.color[0][0] = tempVal / 100
? ? // 使用剛指定的配置項(xiàng)和數(shù)據(jù)顯示圖表。
? ? this.myChart.setOption(option)
? ? tempVal++
? }, 20)
? // 此處監(jiān)聽瀏覽器的resize,重新渲染圖表
? let that = this
? window.addEventListener("resize", function () {
? ? clearTimeout(that.resizeTimer)
? ? that.resizeTimer = setTimeout(() => {
? ? ? myChart.resize()
? ? }, 500)
? })
}以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue采用EventBus實(shí)現(xiàn)跨組件通信及注意事項(xiàng)小結(jié)
EventBus是一種發(fā)布/訂閱事件設(shè)計(jì)模式的實(shí)踐。這篇文章主要介紹了vue采用EventBus實(shí)現(xiàn)跨組件通信及注意事項(xiàng),需要的朋友可以參考下2018-06-06
基于vue2框架的機(jī)器人自動(dòng)回復(fù)mini-project實(shí)例代碼
本篇文章主要介紹了基于vue2框架的機(jī)器人自動(dòng)回復(fù)mini-project實(shí)例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下2017-06-06
vue 獲取及修改store.js里的公共變量實(shí)例
今天小編就為大家分享一篇vue 獲取及修改store.js里的公共變量實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11
Vue中使用clipboard實(shí)現(xiàn)復(fù)制功能
這篇文章主要介紹了Vue中結(jié)合clipboard實(shí)現(xiàn)復(fù)制功能 ,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-09-09
Vue使用axios出現(xiàn)options請(qǐng)求方法
這篇文章主要介紹了Vue使用axios出現(xiàn)options請(qǐng)求,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05

