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

vue中封裝echarts公共組件過程

 更新時(shí)間:2022年05月27日 11:58:48   作者:朵朵和太陽(yáng)  
這篇文章主要介紹了vue中封裝echarts公共組件過程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

定義圖表公共樣式是為了統(tǒng)一同一網(wǎng)站各頁(yè)面圖表的基礎(chǔ)樣式baseOption.js(軸線、區(qū)域、色系、字體),統(tǒng)一封裝后頁(yè)面需要直接引入,傳入所需參即可覆蓋基礎(chǔ)樣式。

以下示例封裝圖表組件Echart.vue。

1、安裝echarts

npm install echarts --save
npm install lodash --save  // 若已安裝請(qǐng)忽略

2、在mian.js中全局引入

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

3、下面開始封裝圖表

baseOption.js文件:公共樣式定義,為了統(tǒng)一同網(wǎng)站各種圖表的基礎(chǔ)樣式,比如軸線、圖各板塊顏色,值僅供參考):

// baseOption.js
export default {
  color: [
    "#0067E1",
    "#0CC1FF",
    "#00D1B3",
    "#85E814",
    "#FFA082",
  ],
  tooltip: {},
  legend: {
    orient:'horizontal',
    type:'scroll',
    pageIconSize:12,
    pageIconColor:'#aaa', 
    pageIconInactiveColor :'#2f4554',
    pageTextStyle:{
      color:'#999999'
    },
    itemWidth:20,
    itemHeight:12,
    top:0,
    textStyle:{
      color:'#999999'
    },
  },
  grid: {
    top: "13%",
    left: "3%",
    right: "10%",
    bottom: "2%",
    containLabel: true,
  },
  xAxis: [
    {
      axisLine: {
        lineStyle: {
          color: "rgba(65, 97, 128, 0.15)",
          // type: "dashed",
        },
      },
      axisTick: {
        show: false,
      },
      axisLabel: {
        interval:0,
        color: "#rgba(0, 0, 0, 0.25)",
        textStyle: {
          fontSize: 10,
        }
      },
      nameTextStyle:{
        color:'#999999',
        fontSize: 10,
      },
    },
  ],
  yAxis: [
    {
      axisLabel: {
        color: "#rgba(0, 0, 0, 0.25)",
        textStyle: {
          fontSize: 11,
        },
      },
      axisLine: {
        lineStyle: {
          color: "rgba(65, 97, 128, 0.15)",
        },
      },
      splitLine: {
        lineStyle: {
          color: "rgba(65, 97, 128, 0.15)",
        },
      },
      axisTick: {
        show: false,
      },
      nameTextStyle:{
        color:'#999999',
        fontSize: 10,
        padding:[0,20,0,0]
      },
      minInterval: 1
    },
  ],
};

Echart.vue文件:圖本身組件

// Echart.vue
<template>
? <div :id="elId" style="height:100%,width:100%" />
</template>
<script>
import echarts from "echarts";
import { merge, debounce } from "lodash";
// 引入公共樣式
import baseOption from "./baseOption"
export default {
? data() {
? ? return {
? ? ? elId: "",
? ? ? vOption: {
? ? ? ? series: [],
? ? ? },
? ? };
? },
? props: {
? ? optionData: Object,
? },
? computed: {
? ? // 合并配置對(duì)象
? ? option() {
? ? ? return merge({}, baseOption, this.vOption, this.optionData);
? ? },
? },
? created() {
? ? this.elId = this.uuid();
? },
? mounted() {
? ? // 實(shí)例化echarts對(duì)象
? ? this.$nextTick(() => {
? ? ? this.initChart();
? ? });
? },
? beforeDestroy() {
? ? if (!this.chart) {
? ? ? return;
? ? }
? ? this.chart.dispose();
? ? this.chart = null;
? },
? watch: {
? ? optionData: {
? ? ? deep: true,
? ? ? handler: function() {
? ? ? ? this.$nextTick(() => {
? ? ? ? ? this.initChart();
? ? ? ? });
? ? ? },
? ? },
? },
? methods: {
? ?? ?// 生成唯一uuid做為唯一標(biāo)識(shí)符
? ? uuid() {
? ? ? return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
? ? ? ? var r = (Math.random() * 16) | 0,
? ? ? ? ? v = c == "x" ? r : (r & 0x3) | 0x8;
? ? ? ? return v.toString(16);
? ? ? });
? ? },
? ? // 繪圖
? ? initChart() {
? ? ? if(!document.getElementById(this.elId)) return
? ? ? this.chart = echarts.init(document.getElementById(this.elId));
? ? ? this.chart.setOption(this.option);
? ? ? const that = this;
? ? ? window.addEventListener(
? ? ? ? "resize",
? ? ? ? debounce(() => { ? ?// 引入debounce,防止頻繁更改瀏覽頁(yè)尺寸出現(xiàn)頁(yè)面抖動(dòng)
? ? ? ? ? if (that.chart) {
? ? ? ? ? ? that.chart.resize();
? ? ? ? ? }
? ? ? ? }, 100)
? ? ? );
? ? },
? },
};
</script>

4、接下來(lái)只需要在需要顯示圖表的地方引入Echart.vue

傳入目標(biāo)數(shù)據(jù)就可以了,以下示例數(shù)據(jù)為餅圖:

// index.vue
<template>
  <div class="chartBox">
    <Chart :optionData="chartData"></Chart>
  </div>
</template>
<script>
// 引入Echart.vue組件
import Chart from "./Echart.vue";
export default {
  components: {
    Chart,
  },
  data() {
    return {
      // 圖目標(biāo)數(shù)據(jù)
      chartData: {
      	tooltip: {
          show:true,
          trigger:'item',
          formatter: " : {c} (wppm3vysvbp%)",
        },
        xAxis: [{ show: false }],
        yAxis: [{ show: false }],
        series: [
          {
            name: "訪問來(lái)源",
            type: "pie", // 餅圖
            radius: ["30%", "45%"], // 餅圖大小
            data: [
              { value: 1048, name: "搜索引擎" },
              { value: 735, name: "直接訪問" },
              { value: 580, name: "郵件營(yíng)銷" },
              { value: 484, name: "聯(lián)盟廣告" },
              { value: 300, name: "視頻廣告" },
            ],
          },
        ],
      },
    };
  },
};
</script>

此時(shí)好看的餅圖就出現(xiàn)啦~~

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue3的setup在el-tab中動(dòng)態(tài)加載組件的方法

    Vue3的setup在el-tab中動(dòng)態(tài)加載組件的方法

    公司某項(xiàng)目需求在頁(yè)面顯示的組件是根據(jù)角色變化而變化的,怎么實(shí)現(xiàn)這個(gè)效果呢,下面小編給大家介紹下Vue3的setup在el-tab中動(dòng)態(tài)加載組件的方法,需要的朋友可以參考下
    2022-11-11
  • Vue.js 事件修飾符的使用教程

    Vue.js 事件修飾符的使用教程

    在實(shí)際開發(fā)中,不可避免的會(huì)使用到對(duì)于事件的操作,如何處理 DOM 事件流,成為我們必須要掌握的技能。這篇文章主要介紹了Vue.js 事件修飾符的使用教程,需要的朋友可以參考下
    2018-11-11
  • vue3使用quill富文本編輯器保姆級(jí)教程(附踩坑解決)

    vue3使用quill富文本編輯器保姆級(jí)教程(附踩坑解決)

    這篇文章主要給大家介紹了關(guān)于vue3使用quill富文本編輯器保姆級(jí)教程的相關(guān)資料,在許多網(wǎng)站和應(yīng)用程序中富文本編輯器是一種常見的工具,它使用戶能夠以直觀的方式創(chuàng)建和編輯文本內(nèi)容,需要的朋友可以參考下
    2023-11-11
  • 詳解Vue 動(dòng)態(tài)添加模板的幾種方法

    詳解Vue 動(dòng)態(tài)添加模板的幾種方法

    本篇文章主要介紹了詳解Vue 動(dòng)態(tài)添加模板的幾種方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧
    2017-04-04
  • vue3響應(yīng)式原理之Ref用法及說(shuō)明

    vue3響應(yīng)式原理之Ref用法及說(shuō)明

    這篇文章主要介紹了vue3響應(yīng)式原理之Ref用法及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • Vue.js暴露方法給WebView的使用操作

    Vue.js暴露方法給WebView的使用操作

    這篇文章主要介紹了Vue.js暴露方法給WebView的使用操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧
    2020-09-09
  • element tree樹形組件回顯數(shù)據(jù)問題解決

    element tree樹形組件回顯數(shù)據(jù)問題解決

    本文主要介紹了element tree樹形組件回顯數(shù)據(jù)問題解決,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • Vue中使用Scss實(shí)現(xiàn)配置、切換主題方式

    Vue中使用Scss實(shí)現(xiàn)配置、切換主題方式

    這篇文章主要介紹了Vue中使用Scss實(shí)現(xiàn)配置、切換主題方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • vue 遞歸組件的簡(jiǎn)單使用示例

    vue 遞歸組件的簡(jiǎn)單使用示例

    這篇文章主要介紹了vue 遞歸組件的簡(jiǎn)單使用示例,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下
    2021-01-01
  • vue中for循環(huán)作用域問題處理方式

    vue中for循環(huán)作用域問題處理方式

    這篇文章主要介紹了vue中for循環(huán)作用域問題處理方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11

最新評(píng)論

如东县| 广平县| 潜江市| 安远县| 万载县| 肥乡县| 泊头市| 句容市| 博白县| 都江堰市| 永安市| 黔西县| 会理县| 咸丰县| 大渡口区| 凯里市| 潼南县| 宁远县| 遵义县| 宝应县| 读书| 大竹县| 道孚县| 清水河县| 兴安盟| 平定县| 宜昌市| 陇南市| 鱼台县| 江油市| 金昌市| 杭州市| 公安县| 武清区| 荆州市| 桂平市| 崇明县| 保亭| 南投县| 堆龙德庆县| 隆子县|