国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

node.js|vue.js|jquery|angularjs|React|json|js教程|

服務器之家 - 編程語言 - JavaScript - vue.js - vue使用echarts畫組織結構圖

vue使用echarts畫組織結構圖

2022-01-19 14:58豫見陳公子 vue.js

這篇文章主要介紹了vue使用echarts畫組織結構圖的示例,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下

昨天,寫了一篇關于圓環進度條的博客(請移步:Vue圓環進度條),已經煩不勝煩,今天又遇到了需要展示類似公司的組織結構圖的功能需求,要冒了!!!

這種需求,自己用div+css也是可以實現的,但是沒有什么動畫效果,我的css3又很差勁,而且項目中已經使用到了折線圖、餅狀圖、柱狀圖之類的圖表,用的還是百度的echarts,所以這個組織結構圖之類的需求也就用了百度的echarts來實現了。

以前用echarts寫折線圖、柱狀圖、餅狀圖的較多,它的API還算比較熟悉,但是畫組織結構這樣的樹狀圖就很苦逼了,沒用過啊,而且設計給的樹狀圖的展示效果跟echarts樹狀圖的展示效果相去甚遠,我滴孩,又得一通費時費力的研究,設計圖如下:

vue使用echarts畫組織結構圖

如圖所示,一個樹節點中可能會有兩種不同的背景色,還有兩種不同的文字顏色,每個節點展示的還是圓角矩形。有同學說了,echarts有設置圓角的API啊,直接設置不就完事了。我想說的是,它是提供的有這樣的API,但是按照正常的套路實現不了啊。

從圖上還可以看到一個幾乎實現不了的效果,就是連接每個節點之間的線的拐角處都是直角而不是平滑的,而且echarts沒有給出可以設置拐角處是直角的API,只是給了一個curveness(API的描述是樹圖邊的曲度),這玩意兒使用了之后,也還是實現不了的。

從網上查了資料,有人說可以修改echarts的源碼,這種解決辦法我不推薦,是因為在vue或react項目中,echarts是需要通過安裝在package.json中的,如果是多人并行開發,那么別人安裝的echarts就不是你修改后的echarts,這就是問題所在。

最后用echarts畫出來的效果還是很不錯的,唯一沒有實現的就是連接每個節點的線的拐角處不是直角,有好的解決辦法的,還望不吝賜教,謝謝!展示一下最終的成果:

vue使用echarts畫組織結構圖

說了那么多,還是上代碼吧,該代碼是基于vue的,如果要使用在react中,稍微修改一下就可以了。

組件tree.vue:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<template>
 <div :class="className" :style="{height:height,width:width}" />
</template>
 
<script>
import echarts from "echarts";
require("echarts/theme/macarons");
import { debounce } from "@/utils";
 
export default {
 props: {
  className: {
   type: String,
   default: "chart"
  },
  width: {
   type: String,
   default: "100%"
  },
  height: {
   type: String,
   default: "500px"
  },
  chartData: {
   type: Object,
   required: true
  }
 },
 data() {
  return {
   chart: null,
  };
 },
 watch: {
  chartData: {
   deep: true,
   handler(val) {
    this.setOptions(val);
   }
  }
 },
 mounted() {
  this.initChart();
  //是否需要自適應-加了防抖函數
  this.__resizeHandler = debounce(() => {
   if (this.chart) {
    this.chart.resize();
   }
  }, 100);
  window.addEventListener("resize", this.__resizeHandler);
 
  // 監聽側邊欄的變化以實現自適應縮放
  const sidebarElm = document.getElementsByClassName("sidebar-container")[0];
  sidebarElm.addEventListener("transitionend", this.sidebarResizeHandler);
 },
 beforeDestroy() {
  if (!this.chart) {
   return;
  }
  window.removeEventListener("resize", this.__resizeHandler);
  this.chart.dispose();
  this.chart = null;
 
  const sidebarElm = document.getElementsByClassName("sidebar-container")[0];
  sidebarElm.removeEventListener("transitionend", this.sidebarResizeHandler);
 },
 methods: {
  initChart() {
   this.chart = echarts.init(this.$el, "macarons");
   this.setOptions(this.chartData);
  
   const nodes = this.chart._chartsViews[0]._data._graphicEls;
   let allNode = 0;
   for(let index = 0; index < nodes.length; index++) {
    const node = nodes[index];
    if (node === undefined) {
     continue
    }
    allNode++;
   }
   
   const height = window.innerHeight;
   const width = window.innerWidth - 1000;
   const currentHeight = 85 * allNode;
   const currentWidth = 220 * allNode;
   const newHeight = Math.max(currentHeight, height);
   const newWidth = Math.max(currentWidth, width);
   const tree_ele = this.$el;
   // tree_ele.style.height = newHeight + 'px'; //設置高度自適應
   tree_ele.style.width = newWidth + 'px';  //設置寬度自適應
   this.chart.resize();
 
   this.chart.on('click', this.chartData.clickCallback);  //節點點擊事件
  },
  setOptions(data) {
   this.chart.setOption({
    //提供數據視圖、還原、下載的工具
    // toolbox: {
    //  show : true,
    //  feature : {
    //   mark : {show: true},
    //   dataView : {show: true, readOnly: false},
    //   restore : {show: true},
    //   saveAsImage : {show: true}
    //  }
    // },
    series: [
     {
      name: "統一授信視圖",
      type: "tree",
      orient: "TB", //豎向或水平  TB代表豎向 LR代表水平
      top: '10%',
      initialTreeDepth: 10, //樹圖初始展開的層級(深度)
      expandAndCollapse: false,  //點擊節點時不收起子節點,default: true
      symbolSize: [135, 65],
      itemStyle: {
       color: 'transparent',
       borderWidth: 0,
      },
      lineStyle: {
       color: '#D5D5D5',
       width: 1,
       curveness: 1,
      },
      data: [data]
     }
    ]
   });
  },
  sidebarResizeHandler(e) {
   if (e.propertyName === "width") {
    this.__resizeHandler();
   }
  }
 }
};
</script>

使用tree.vue的方法:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<template>
  <tree :chartData="treeData" />
</template>
 
<script>
import tree from './tree';
 
export default {
 data() {
  return {
   treeData: {
    label: {
     backgroundColor: '#F4F4F4',
     borderRadius: [0, 0, 5, 5],
     formatter: [
      '{first|綜合授信額度}',
      '{second|(CR20190912000013)\n獲批金額:100\n幣種:人民幣}',
     ].join('\n'),
     rich: {
      first: {
       backgroundColor: '#078E34',
       color: '#fff',
       align: 'center',
       width: 135,
       height: 30,
       borderRadius: [5, 5, 0, 0],
      },
      second: {
       color: '#888',
       align: 'center',
       lineHeight: 17,
      },
     }
    },
    children: [
     {
      label: {
       formatter: [
        '{first|渠道額度}',
       ].join('\n'),
       rich: {
        first: {
         backgroundColor: '#3AC082',
         color: '#fff',
         align: 'center',
         width: 135,
         height: 65,
         borderRadius: 5,
        },
       }
      },
      children: [{
       label: {
        formatter: [
         '{first|保理額度}',
        ].join('\n'),
        rich: {
         first: {
          backgroundColor: '#3AC082',
          color: '#fff',
          align: 'center',
          width: 135,
          height: 65,
          borderRadius: 5,
         },
        }
       },
       children: [{
        label: {
         backgroundColor: '#F4F4F4',
         borderRadius: [0, 0, 5, 5],
         formatter: [
          '{first|反向保理}',
          '{second|(CR20190912000013)\n獲批金額:100\n幣種:人民幣}',
         ].join('\n'),
         rich: {
          first: {
           backgroundColor: '#078E34',
           color: '#fff',
           align: 'center',
           width: 135,
           height: 30,
           borderRadius: [5, 5, 0, 0],
          },
          second: {
           color: '#888',
           align: 'center',
           lineHeight: 17,
          },
         }
        },
       }]
      }]
     },
     {
      label: {
       formatter: [
        '{first|擔保/(樂)集團/其他額度}',
       ].join('\n'),
       rich: {
        first: {
         backgroundColor: '#3AC082',
         color: '#fff',
         align: 'center',
         width: 135,
         height: 65,
         borderRadius: 5,
        },
       }
      },
      children: [{
       label: {
        formatter: [
         '{first|保理額度}',
        ].join('\n'),
        rich: {
         first: {
          backgroundColor: '#3AC082',
          color: '#fff',
          align: 'center',
          width: 135,
          height: 65,
          borderRadius: 5,
         },
        }
       },
       children: [{
        label: {
         backgroundColor: '#F4F4F4',
         borderRadius: [0, 0, 5, 5],
         formatter: [
          '{first|正向保理}',
          '{second|(CR20190912000013)\n獲批金額:100\n幣種:人民幣}',
         ].join('\n'),
         rich: {
          first: {
           backgroundColor: '#B8D87E',
           color: '#fff',
           align: 'center',
           width: 135,
           height: 30,
           borderRadius: [5, 5, 0, 0],
          },
          second: {
           color: '#888',
           align: 'center',
           lineHeight: 17,
          },
         }
        },
       }]
      },
      {
       label: {
        formatter: [
         '{first|租賃額度}',
        ].join('\n'),
        rich: {
         first: {
          backgroundColor: '#3AC082',
          color: '#fff',
          align: 'center',
          width: 135,
          height: 65,
          borderRadius: 5,
         },
        }
       },
       children: [
        {
         label: {
          backgroundColor: '#F4F4F4',
          borderRadius: [0, 0, 5, 5],
          formatter: [
           '{first|車輛租賃}',
           '{second|(CR20190912000013)\n獲批金額:100\n幣種:人民幣}',
          ].join('\n'),
          rich: {
           first: {
            backgroundColor: '#FF6C6A',
            color: '#fff',
            align: 'center',
            width: 135,
            height: 30,
            borderRadius: [5, 5, 0, 0],
           },
           second: {
            color: '#888',
            align: 'center',
            lineHeight: 17,
           },
          }
         },
        },
       ]
      }]
     }
    ]
   }
  }
 },
 components: {
  tree,
 }
};
</script>

看著代碼不多,但是實現起來,各種查echarts的API和網上的資料,而且,由于效果圖中一個節點處的文字可能會換行,文字的顏色也不同,同時有些節點處的背景色還會有兩種,以及每個節點處顯示的樣式和文字都是不固定的,所以我們可能還要面臨著將接口返回的數據再改造處理成我們想要的數據的繁瑣問題,就如同傳遞給樹節點的treeData的格式一樣,相當麻煩,如果每個節點的樣式都是一樣的,那就好辦多了,如官網的一個樹狀圖的例子:https://www.echartsjs.com/examples/zh/editor.html?c=tree-vertical

從echarts的v4.7.0版本開始,給配置項series中加入一個API:edgeShape:'polyline'可實現樹形圖表連接每個節點的線的拐角處呈直角。

以上就是vue使用echarts畫組織結構圖的詳細內容,更多關于vue 畫組織結構圖的資料請關注服務器之家其它相關文章!

原文鏈接:https://www.cnblogs.com/tnnyang/p/11663217.html

延伸 · 閱讀

精彩推薦
  • vue.jsVue2.x-使用防抖以及節流的示例

    Vue2.x-使用防抖以及節流的示例

    這篇文章主要介紹了Vue2.x-使用防抖以及節流的示例,幫助大家更好的理解和學習使用vue框架,感興趣的朋友可以了解下...

    Kyara6372022-01-25
  • vue.js詳解vue 表單綁定與組件

    詳解vue 表單綁定與組件

    這篇文章主要介紹了vue 表單綁定與組件的相關資料,幫助大家更好的理解和學習使用vue框架,感興趣的朋友可以了解下...

    Latteitcjz6432022-02-12
  • vue.jsVue中引入svg圖標的兩種方式

    Vue中引入svg圖標的兩種方式

    這篇文章主要給大家介紹了關于Vue中引入svg圖標的兩種方式,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的...

    十里不故夢10222021-12-31
  • vue.jsVue2.x 項目性能優化之代碼優化的實現

    Vue2.x 項目性能優化之代碼優化的實現

    這篇文章主要介紹了Vue2.x 項目性能優化之代碼優化的實現,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋...

    優小U9632022-02-21
  • vue.jsVue項目中實現帶參跳轉功能

    Vue項目中實現帶參跳轉功能

    最近做了一個手機端系統,其中遇到了父頁面需要攜帶參數跳轉至子頁面的問題,現已解決,下面分享一下實現過程,感興趣的朋友一起看看吧...

    YiluRen丶4302022-03-03
  • vue.jsVue多選列表組件深入詳解

    Vue多選列表組件深入詳解

    這篇文章主要介紹了Vue多選列表組件深入詳解,這個是vue的基本組件,有需要的同學可以研究下...

    yukiwu6752022-01-25
  • vue.js用vite搭建vue3應用的實現方法

    用vite搭建vue3應用的實現方法

    這篇文章主要介紹了用vite搭建vue3應用的實現方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下...

    Asiter7912022-01-22
  • vue.js梳理一下vue中的生命周期

    梳理一下vue中的生命周期

    看過很多人講vue的生命周期,但總是被繞的云里霧里,尤其是自學的同學,可能js的基礎也不是太牢固,聽起來更是吃力,那我就已個人之淺見,以大白話...

    CRMEB技術團隊7992021-12-22
主站蜘蛛池模板: 综合久久久久 | 久久久777 | 91久久国产精品 | 伊人中文| 日韩视频不卡 | 成人免费视频亚洲 | 国产激情在线视频 | 51ⅴ精品国产91久久久久久 | 国产精品中文字幕在线观看 | 99精品国产高清一区二区麻豆 | 黄色一级大片在线免费看产 | 欧美成人毛片 | 欧美综合色 | 狠狠ri| 国产片性视频免费播放 | 亚洲欧美一级久久精品国产特黄 | 午夜精品美女久久久久av福利 | 亚洲精品久久 | 一区二区精品在线视频 | 在线国产小视频 | 啪啪导航 | 欧美精品一区二区三区蜜桃视频 | 在线国产精品一区 | 国产精品久久一区 | 日韩中文字幕在线播放 | 日韩在线成人 | 激情综合婷婷 | 欧美在线视频一区 | 精品国产色 | 精品成人av| 欧美日韩在线免费 | 国产精品一区一区三区 | 先锋av资源在线 | 欧美一区国产一区 | 精品中文字幕一区 | 精品久久久久久久 | 亚洲精品第一 | 欧美日韩在线播放 | 69中文字幕 | 色精品 | 日本黄色a视频 |