vue中使用Echarts

安裝引入

npm install echarts --save
import Echarts from 'echarts'

環(huán)狀圖

<div id="pieChart" class="chart-container"></div>
.chart-container {
  border-radius: 4px;
  height: 400px;
  background: #fff;
  box-shadow: 0 1px 10px 2px rgba(182, 191, 196, 0.5);
  padding: 20px;
}
data() {
    return { 
      pieCharts: null,     
      pieOption: {
        title: {
          text: '星級(jí)分布'
        },
        tooltip: {
          trigger: 'item',
          formatter: "{a} <br/>: {c} (u0z1t8os%)"
        },
        series: [
          {
            name: '訪(fǎng)問(wèn)來(lái)源',
            type: 'pie',
            radius: ['50%', '70%'],
            avoidLabelOverlap: true,
            label: {
              emphasis: {
                show: true,
                textStyle: {
                  fontSize: '30',
                  fontWeight: 'bold'
                }
              }
            },
            data: [
              { value: 335, name: '二星' },
              { value: 310, name: '三星' },
              { value: 234, name: '四星' },
              { value: 135, name: '五星' }
            ]
          }
        ]
      }    
    }
},
mounted() {
    this.$nextTick(() => {      
      this.pieCharts = Echarts.init(document.getElementById('pieChart'))
      this.pieCharts.setOption(this.pieOption)
      window.addEventListener('resize', this.handleResize)
    })
},
methods: {
    handleResize() {
      this.pieCharts.resize()
    },
},
beforeDestroy() {
    window.removeEventListener('resize', this.handleResize)
    this.pieCharts.dispose()
}

折線(xiàn)圖

<div id="lineChart" class="chart-container"></div>
data() {
    return {
      lineCharts: null,
      lineOption: {
        title: {
          text: '消費(fèi)逐月消費(fèi)趨勢(shì)'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['差旅', '個(gè)人']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        toolbox: {
          feature: {
            saveAsImage: {
              show: false
            }
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
        },
        yAxis: {
          type: 'value',
          name: '(萬(wàn))',
          nameLocation: 'start',
          nameTextStyle: {
            fontSize: 14,
            padding: [0, 50, 0, 0],
          }
        },
        series: [
          {
            name: '差旅',
            type: 'line',
            stack: '總量',
            data: [120, 132, 101, 134, 90, 230, 210, 120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: '個(gè)人',
            type: 'line',
            stack: '總量',
            data: [220, 182, 191, 234, 290, 330, 310, 120, 132, 101, 134, 90, 230, 210]
          }
        ]
      }      
    }
},
mounted() {
    this.$nextTick(() => {
      this.lineCharts = Echarts.init(document.getElementById('lineChart'))
      this.lineCharts.setOption(this.lineOption)
      window.addEventListener('resize', this.handleResize)
    })
},
methods: {
    handleResize() {
      this.lineCharts.resize()
    },
},
beforeDestroy() {
    window.removeEventListener('resize', this.handleResize)
    this.lineCharts.dispose()
}

網(wǎng)站導(dǎo)航

網(wǎng)站導(dǎo)航

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容