zoukankan      html  css  js  c++  java
  • vuejs中使用echart图表

    首先安装echart
    npm i echarts -S
    加下来以使用这个图表为例
    在vue组件中像这样使用:

    <template>
      <div :class="className" :id="id" :style="{height:height,width}" ref="myEchart">
      </div>
    </template>
    <script>
    import echarts from 'echarts'
    export default {
      props: {
        className: {
          type: String,
          default: 'yourClassName'
        },
        id: {
          type: String,
          default: 'yourID'
        },
         {
          type: String,
          default: '500px'
        },
        height: {
          type: String,
          default: '500px'
        }
      },
      data() {
        return {
          chart: null
        }
      },
      mounted() {
        this.initChart();
      },
      beforeDestroy() {
        if (!this.chart) {
          return
        }
        this.chart.dispose();
        this.chart = null;
      },
      methods: {
        initChart() {
          this.chart = echarts.init(this.$refs.myEchart);
          // 把配置和数据放这里
          this.chart.setOption({
            color: ['#3398DB'],
            tooltip: {
              trigger: 'axis',
              axisPointer: { // 坐标轴指示器,坐标轴触发有效
                type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
              }
            },
            grid: {
              left: '3%',
              right: '4%',
              bottom: '3%',
              containLabel: true
            },
            xAxis: [{
              type: 'category',
              data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
              axisTick: {
                alignWithLabel: true
              }
            }],
            yAxis: [{
              type: 'value'
            }],
            series: [{
              name: '直接访问',
              type: 'bar',
              barWidth: '60%',
              data: [10, 52, 200, 334, 390, 330, 220]
            }]
          })
        }
      }
    }
    </script>
    

    如果是异步获取的数据,比如用axios,那只需要把配置项放到then方法后面:

        initChart() {
          this.chart = echarts.init(this.$refs.myEchart);
          // 把配置和数据放这里
          this.axios.get('/url').then((data) => {
          	this.chart.setOption({
    
          	})
          })
        }
    
  • 相关阅读:
    Android Activity 四种启动模式
    Android Activity的生命周期
    Android SQLite (五 ) 全面详解(三)
    Android SQLite (四 ) 全面详解(二)
    工作流设计 zt
    法律网站分类 ­zt
    刑事案件的构成要素 zt
    犯罪构成三层次记忆口诀 zt
    E asy Boo t 6.51 启动易 制作启动光盘的软件(附注册码)
    父线程开启子进程且共享内存
  • 原文地址:https://www.cnblogs.com/yesyes/p/7161923.html
Copyright © 2011-2022 走看看