最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Ionic3實現(xiàn)選項卡切換并重新加載echarts

 更新時間:2020年09月24日 11:31:11   作者:賈樹丙  
這篇文章主要介紹了基于Ionic3實現(xiàn)選項卡切換并重新加載echarts,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

要求

選項卡每切換一次,就加載對應(yīng)的一個echarts 圖,要有一開始的動畫效果

效果如下:

注意點

1、echarts要想每次都能重新加載,需要移除"_echarts_instance_"屬性,否則一切換選項卡,就再也加載不出來了

2、在ts 中獲取html 頁面元素,不能寫在構(gòu)造方法里,應(yīng)該寫在ionViewDidEnter()方法里

3、選項卡<ion-segment> 不要搭配[ngSwitch] 的方式,因為這種情況下,只能獲取當(dāng)前選項卡中的元素,未選中的選項卡里的元素獲取不到,在第2步驟ionViewDidEnter() 方法里自然也是獲取不到。應(yīng)當(dāng)搭配(ionChange)使用方式

4、不能直接將chart作為全局變量,這樣的話第二次加載就沒有動畫效果了

獻上代碼

html文件

<ion-header>
 <ion-navbar>
  <ion-title>區(qū)域</ion-title>
 </ion-navbar>

</ion-header>

<ion-content padding>

  <ion-segment [(ngModel)]="choice" (ionChange)="segmentChanged($event)">
   <ion-segment-button value="choice1">
    省份增速排名
   </ion-segment-button>
   <ion-segment-button value="choice2">
    市州增速排名
   </ion-segment-button>
   <ion-segment-button value="choice3">
    全省走勢
   </ion-segment-button>
   <ion-segment-button value="choice4">
    市州占比
   </ion-segment-button>
  </ion-segment>

  <div id="chartContainer" style="width: 100%; height: 300px;"></div>

</ion-content>

ts文件

import {Component} from '@angular/core';
import * as echarts from 'echarts';

@Component({
 selector: 'page-data-area',
 templateUrl: 'area.html'
})
export class DataAreaPage {
 choice: string = "choice1";
 ec: any = echarts;
 chartContainer: any;

 constructor() {
 }

 clickChart1() {
  const chart1 = this.ec.init(this.chartContainer);
  chart1.setOption({
   series: {
    type: 'pie',
    data: [{
     name: 'A',
     value: 10
    }, {
     name: 'B',
     value: 20
    }, {
     name: 'C',
     value: 30
    }, {
     name: 'D',
     value: 40
    }]
   }
  }, true);
  this.chartContainer.removeAttribute("_echarts_instance_");
 }

 clickChart2() {
  const chart2 = this.ec.init(this.chartContainer);
  chart2.setOption({
   series: {
    type: 'pie',
    data: [{
     name: 'A',
     value: 10
    }, {
     name: 'B',
     value: 20
    }, {
     name: 'C',
     value: 30
    }]
   }
  }, true);
  this.chartContainer.removeAttribute("_echarts_instance_");
 }

 clickChart3() {
  const chart3 = this.ec.init(this.chartContainer);
  chart3.setOption({
   series: {
    type: 'pie',
    data: [{
     name: 'A',
     value: 10
    }, {
     name: 'B',
     value: 20
    }, {
     name: 'C',
     value: 30
    }, {
     name: 'D',
     value: 40
    }, {
     name: 'E',
     value: 50
    }]
   }
  }, true);
  this.chartContainer.removeAttribute("_echarts_instance_");
 }

 clickChart4() {
  const chart4 = this.ec.init(this.chartContainer);
  chart4.setOption({
   series: {
    type: 'pie',
    data: [{
     name: 'A',
     value: 10
    }, {
     name: 'B',
     value: 20
    }, {
     name: 'C',
     value: 30
    }, {
     name: 'D',
     value: 40
    }, {
     name: 'E',
     value: 50
    }, {
     name: 'F',
     value: 60
    }]
   }
  }, true);
  this.chartContainer.removeAttribute("_echarts_instance_");
 }

 segmentChanged(e) {
  if (e.value == "choice1") {
   this.clickChart1();
  } else if (e.value == "choice2") {
   this.clickChart2();
  } else if (e.value == "choice3") {
   this.clickChart3();
  } else if (e.value == "choice4") {
   this.clickChart4();
  }
 }

 ionViewDidEnter() {
  this.chartContainer = document.getElementById('chartContainer');
  this.clickChart1();
 }

}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

南召县| 固阳县| 子长县| 察雅县| 西宁市| 洛浦县| 阳城县| 湖州市| 西乌| 陈巴尔虎旗| 盐池县| 安泽县| 油尖旺区| 抚州市| 尼木县| 隆子县| 安西县| 修武县| 永修县| 铜山县| 通江县| 阳泉市| 上虞市| 增城市| 丰顺县| 汪清县| 南皮县| 会昌县| 裕民县| 台湾省| 平潭县| 卓尼县| 阜阳市| 巴林右旗| 类乌齐县| 都江堰市| 金门县| 玉门市| 九台市| 富裕县| 玉田县|