vue2.0 自定義 餅狀圖 (Echarts)組件的方法
1、自定義 圖表 組件
Echarts.vue
<!-- 自定義 echart 組件 --> <template> <div> <!-- echart表格 --> <div id="myChart" :style="echartStyle"></div> </div> </template> <script> export default { props: { // 樣式 echartStyle: { type: Object, default(){ return {} } }, // 標(biāo)題文本 titleText: { type: String, default: '' }, // 提示框鍵名 tooltipFormatter: { type: String, default: '' }, // 扇形區(qū)域名稱 opinion: { type: Array, default(){ return [] } }, // 提示框標(biāo)題 seriesName: { type: String, default: '' }, // 扇形區(qū)域數(shù)據(jù) opinionData: { type: Array, default(){ return [] } }, }, data(){ return { // } }, mounted(){ this.$nextTick(function() { this.drawPie('myChart') }) }, methods: { // 監(jiān)聽扇形圖點(diǎn)擊 eConsole(param) { // 向父組件傳值 this.$emit("currentEchartData",param.name); }, // 繪制餅狀圖 drawPie(id){ this.charts = this.$echarts.init(document.getElementById(id)); this.charts.on("click", this.eConsole); this.charts.setOption({ title: { text: this.titleText, // 標(biāo)題文本 left: 'center' }, tooltip : { trigger: 'item', formatter: "{a} <br/> " + this.tooltipFormatter + ":{c}" }, legend: { bottom: 20, left: 'center', data: this.opinion // 扇形區(qū)域名稱 }, series : [ { name:this.seriesName, // 提示框標(biāo)題 type: 'pie', radius : '65%', center: ['50%', '50%'], selectedMode: 'single', data:this.opinionData, // 扇形區(qū)域數(shù)據(jù) itemStyle: { emphasis: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' } } } ] }) } } } </script> <style lang="less" scoped> #myChart{ width: 100%; } </style>
2、頁面調(diào)用
Diagram.vue
<!-- 圖表 --> <template> <div> <!-- 標(biāo)題欄 --> <mt-header title="圖表"> <router-link to="/" slot="left"> <mt-button icon="back">返回</mt-button> </router-link> </mt-header> <!-- 內(nèi)容 --> <m-echarts :echartStyle="s" :titleText="a" :tooltipFormatter="b" :opinion="c" :seriesName="d" :opinionData="e" v-on:currentEchartData="getEchartData" ></m-echarts> </div> </template> <script> import mEcharts from '../components/Echarts' export default { name: 'Diagram', components: { mEcharts }, data(){ return { a:'水果銷售統(tǒng)計(jì)', b:'銷售數(shù)量', c:['香蕉','蘋果','橘子'], d:'銷售統(tǒng)計(jì)', e:[ {value:3, name:'香蕉'}, {value:3, name:'蘋果'}, {value:3, name:'橘子'} ], s: { height: '' } } }, created(){ // 獲取屏幕高度 this.s.height = document.documentElement.clientHeight - 44 + 'px'; }, methods: { getEchartData(val){ console.log(val); } } } </script> <style lang="less" scoped> // </style>
3、效果圖
以上這篇vue2.0 自定義 餅狀圖 (Echarts)組件的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue雙向錨點(diǎn)實(shí)現(xiàn)過程簡(jiǎn)易版(scrollIntoView)
這篇文章主要介紹了vue雙向錨點(diǎn)實(shí)現(xiàn)過程簡(jiǎn)易版(scrollIntoView),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07Vue實(shí)現(xiàn)購物車的全選、單選、顯示商品價(jià)格代碼實(shí)例
這篇文章主要介紹了Vue實(shí)現(xiàn)購物車的全選、單選、顯示商品價(jià)格實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05vue組件(全局,局部,動(dòng)態(tài)加載組件)
組件是Vue.js最強(qiáng)大的功能之一。組件可以擴(kuò)展HTML元素,封裝可重用的代碼。這篇文章主要介紹了vue組件(全局,局部,動(dòng)態(tài)加載組件),需要的朋友可以參考下2018-09-09vue基于websocket實(shí)現(xiàn)智能聊天及吸附動(dòng)畫效果
這篇文章主要介紹了vue基于websocket實(shí)現(xiàn)智能聊天及吸附動(dòng)畫效果,主要功能是基于websocket實(shí)現(xiàn)聊天功能,封裝了一個(gè)socket.js文件,使用Jwchat插件實(shí)現(xiàn)類似QQ、微信電腦端的功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-07-07vue項(xiàng)目創(chuàng)建步驟及路由router
本文主要給大家分享了vue項(xiàng)目的創(chuàng)建步驟以及vue路由router的相關(guān)知識(shí)點(diǎn),非常的實(shí)用,有需要的小伙伴可以來參考下2020-01-01vue項(xiàng)目實(shí)現(xiàn)背景顏色以及下劃線從左到右漸變動(dòng)畫效果
這篇文章主要介紹了vue項(xiàng)目實(shí)現(xiàn)背景顏色以及下劃線從左到右漸變動(dòng)畫效果,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08