1. 程式人生 > 其它 >vue 中使用多個echarts 適應螢幕縮放

vue 中使用多個echarts 適應螢幕縮放

data () {
    return {
        resizeTimer: null,
        myChart1: null,
        myChart2: null,
        myChart3: null,
        myChart4: null
    }
},
methods: {
     // 綜合得分 雷達圖
      getScoreChart () {
        let myChart = window.echarts.init(document.getElementById('compositeScore'))
        myChart.clear()
        
this.myChart1 = myChart myChart.setOption(this.option) }, // 園區人員柱狀圖 getPersonChart () { let myChart = window.echarts.init(document.getElementById('personChart')) myChart.clear() this.myChart2 = myChart myChart.setOption(this.personOption) },
// 車輛資訊 柱狀折線圖 getcarInfoChart () { let myChart = window.echarts.init(document.getElementById('carInfoChart')) myChart.clear() this.myChart3 = myChart myChart.setOption(this.carInfoOption) }, // 今日用能 折線柱狀圖 getTodayEnergyOption() { let myChart
= window.echarts.init(document.getElementById('todayEnergy')) myChart.clear() this.myChart4 = myChart myChart.setOption(this.todayEnergyOption) } }, mounted () { this.$nextTick(function(){ let _t = this setTimeout(function(){ _t.initSwiper() },500) // swiper 初始化 (因為dom渲染完成才能初始化Swiper,所以必須將初始化放入vue的生命週期鉤子函式mounted中:) // new Swiper('.swiper-container', { // pagination: '.swiper-pagination', // paginationClickable: true, // observer:true,//啟動動態檢查器(OB/觀眾/觀看者),當改變swiper的樣式(例如隱藏/顯示)或者修改swiper的子元素時,自動初始化swiper。 // observeParents:true,//將observe應用於Swiper的父元素。當Swiper的父元素變化時,例如window.resize,Swiper更新 // direction: 'vertical', // autoplay: 2000 // }) }) // // 出租率 // // this.common.characteristicAlarm('pie3','#00C1B1','#30E2DF','30','70') // this.common.characteristicAlarm('pie4','#0D9DFE','#0D9DFE','30','70') // this.common.characteristicAlarm('pie5','#00C1B1','#30E2DF','30','70') // this.common.characteristicAlarm('pie6','#00C1B1','#30E2DF','30','70') // this.common.characteristicAlarm('pie7','#00C1B1','#30E2DF','30','70') // this.common.characteristicAlarm('pie8','#00C1B1','#30E2DF','30','70') // // // 企業總數環形 this.common.drawPie('park-pie1') // this.common.drawPie('park-pie3') let _this = this; window.addEventListener('resize', function () { if (_this.resizeTimer) clearTimeout(_this.resizeTimer); _this.resizeTimer = setTimeout(function () { _this.myChart1.resize(); _this.myChart2.resize(); _this.myChart3.resize(); _this.myChart4.resize(); }, 100) }) }