Vue使用echarts資料動態更新,Y軸刻度固定或者自適應

來源:互聯網
上載者:User

前幾天在Vue項目中使用到了echarts,所以寫個簡單的小Demo 想要實現的效果 資料動態產生(即時改變) 時間點1
時間點2
代碼 檔案(Echarts.vue)

<template>  <div class="echarts">    <i-echarts :option="options"></i-echarts>  </div></template><script>  import IEcharts from 'vue-echarts-v3/src/full.vue'  export default {    name: 'table',    components: {      IEcharts    },    data() {      return {        options: {          title: {            text: 'Timesky'          },          tooltip: {            trigger: 'item'          },          legend: {            data: ['銷量']          },          xAxis: {            name: '商品',            nameLocation: 'start',            nameGap: '50',            boundaryGap: true,            data: ['襯衫', '羊毛衫', '雪紡衫', '褲子', '高跟鞋', '襪子']          },          // yAxis: {},      縱軸自適應          yAxis: {          //縱軸尺規固定              type: 'value',              scale: true,              name: '銷量',              max: 100,              min: 0,              boundaryGap: [0.2, 0.2]          },          series: [{            name: '銷量',            type: 'bar',            data: [5, 20, 36, 60, 10, 55]          }]        }      }    },    mounted() {      this.changeData()    },    methods: {      changeData() {        let data = []        for (let i = 0, min = 5, max = 99; i < 6; i++) {          data.push(Math.floor(Math.random() * (max + 1 - min) + min))        }        this.options.series[0].data = data        setTimeout(this.changeData, 2000)      }    }  }</script><style>  .echarts {    width: 800px;    height: 400px;  }</style>
Y軸刻度自適應與固定 如上段代碼中注釋所示,預設情況下是自適應的,效果如下

若想固定縱軸只需配置min和max值即可 若想分更多刻度可以配置splitNumber屬性
 // yAxis: {},      //縱軸自適應 yAxis: {          //縱軸尺規固定      type: 'value',      scale: true,      name: '銷量',      max: 100,      min: 0,      splitNumber:10,      boundaryGap: [0.2, 0.2]  },

效果如下


  本文參考博文 JavaScript eChart yAxis 固定值 變化值 echarts官網執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.