vue集成echarts

第一步,安裝echarts包

npm install echarts --save

第二步,vue頁面直接引用

<template>
  <div ref="container" class="content"></div>
</template>

<script>
  import echarts from 'echarts'
  require('echarts/theme/macarons')
  export default {
      name: "lineChart",
      data(){
        return{

        }
      },
    methods:{
      // 初始化echart
      initChart () {
        var myChart = echarts.init(this.$refs.container);
        myChart.setOption({
          color: ['#3398DB'],
          tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐標(biāo)軸指示器,坐標(biāo)軸觸發(fā)有效
              type : 'shadow'        // 默認(rèn)為直線,可選為:'line' | 'shadow'
            }
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis : [
            {
              type : 'category',
              data : ['08-07', '08-08', '08-09', '08-10', '08-11', '08-12', '08-13'],
              axisTick: {
                alignWithLabel: true
              }
            }
          ],
          yAxis : [
            {
              type : 'value'
            }
          ],
          series : [
            {
              name:'總共',
              type:'bar',
              barWidth: '60%',
              data:[10, 52, 200, 334, 390, 330, 220]
            }
          ]
        });
      }
    },
    mounted () {
      this.$nextTick(() => {
        this.initChart();
      })
    }

  }
</script>

<style scoped>
  .content{
    display: flex;
    flex-direction: row;
    align-content: center;
    align-items: center;
    height: 500px;
    width: 500px;
  }
</style>

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

相關(guān)閱讀更多精彩內(nèi)容

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