VUE+elementui組件在table-cell單元格中繪制微型echarts圖
需求效果圖示例
實(shí)際完成效果圖
**
代碼實(shí)現(xiàn)
注:table表格為二次封裝的子組件
-在table表格中 根據(jù) scope.$index動(dòng)態(tài)設(shè)置元素的id ,便于指定單元格的echarts初始化;
-在單元格中觸發(fā)一個(gè)方法,傳入當(dāng)前的scope.row數(shù)據(jù)或者指定其他數(shù)據(jù),并且傳入 scope.$index 以及一個(gè)字符串便于識別當(dāng)前是哪條數(shù)據(jù)的charts
-在方法中繪制echarts**
<el-table-column align="center"> <template slot="header" slot-scope="scope"> <div v-if="tableTitle == 'sale'"> <p v-if="dateType != '1'"> 近{{ dateType }}天累計(jì) <br /> / 日均銷量 </p> <p v-if="dateType == '1'">昨日累計(jì)銷量</p> </div> <div v-if="tableTitle == 'fav'"> <p v-if="dateType != '1'"> 近{{ dateType }}天累計(jì) <br /> / 日均收藏量 </p> <p v-if="dateType == '1'">昨日累計(jì)收藏</p> </div> </template> <div slot-scope="scope" style="white-space:nowrap;"> <span class="xiao-red-color">{{ realRowName(scope.row, '0') || '-' }}</span> <span v-if="dateType != '1'" class="xiao-red-color"> / {{ isNaN(realRowName(scope.row, '0')) ? '-' : (realRowName(scope.row, '0') / (parseInt(dateType) - calcShelfTime(scope.row.real_created_time, '0') < 0 ? parseInt(dateType): calcShelfTime(scope.row.real_created_time, '0'))).toFixed(0)}} </span> </div> </el-table-column> <el-table-column label="每日銷量趨勢" align="center" v-if="dateType != '1'"> <template slot-scope="scope"> {{ drawEcharts(scope.row, scope.$index, 'sale') }} <div :id="`tiger-sale-trend-index` + scope.$index" class="tiger-trend-charts"></div> </template> </el-table-column>
繪制echarts的方法(數(shù)據(jù)僅為示例,實(shí)際開發(fā)根據(jù)傳進(jìn)來的scope.row數(shù)據(jù))注意此處初始化echarts對象時(shí)采用VUE的this.$nextTick方法,以防獲取不到未渲染的節(jié)點(diǎn)元素。
drawEcharts() { //繪制趨勢echarts // console.log(arguments) let option = { tooltip: { trigger: 'axis' }, // legend: { // data: ['每日30天銷量分析'] // }, grid: { left: '10px', right: '30px', top: '40px', bottom: '10px', containLabel: true }, xAxis: { show: false, type: 'category', boundaryGap: false, data: ['03-21', '03-22', '03-23', '03-24', '03-25', '03-26', '03-27'] }, yAxis: { show: false, type: 'value' }, series: [ { name: '每日30天銷量分析', type: 'line', data: [120, 500, 101, 86, 173, 230, 6] } ] }; let chartId = 'tiger-' + arguments[2] + '-trend-index' + arguments[1]; this.$nextTick(() => { let myChart = this.echarts.init(document.getElementById(chartId), 'macarons'); myChart.setOption(option); myChart.resize(); }); },
AND 不要忘記設(shè)置echarts的高度,否則一輩子也出不來圖形(示例,根據(jù)實(shí)施開發(fā)調(diào)整)
&-frame { display: flex; flex-flow: column nowrap; justify-content: space-between; .price-bar { color: red !important; } .tiger-trend-charts { height: 60px; min-width: 100px; } }
到此這篇關(guān)于VUE+elementui組件在table-cell單元格中繪制微型echarts圖的文章就介紹到這了,更多相關(guān)VUE elementui 單元格echarts圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
解決Vue調(diào)用springboot接口403跨域問題
這篇文章主要介紹了解決Vue調(diào)用springboot接口403跨域問題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09如何利用vue+element?ui實(shí)現(xiàn)好看的登錄界面
最近做了個(gè)最基礎(chǔ)的ElementUI登錄頁,適合新手查看,所以下面這篇文章主要給大家介紹了關(guān)于如何利用vue+element?ui實(shí)現(xiàn)好看的登錄界面的相關(guān)資料,需要的朋友可以參考下2022-05-05vue-cli3+typescript初體驗(yàn)小結(jié)
這篇文章主要介紹了vue-cli3+typescript初體驗(yàn)小結(jié),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-02-02vue項(xiàng)目實(shí)現(xiàn)頁面跳轉(zhuǎn)的方法
這篇文章主要給大家分享的是vue項(xiàng)目實(shí)現(xiàn)頁面跳轉(zhuǎn)的方法,vue-router是前端開發(fā)中用來實(shí)現(xiàn)路由頁面跳轉(zhuǎn)的一個(gè)模塊。下面小編將帶來如何在已經(jīng)創(chuàng)建好的vue-router項(xiàng)目基礎(chǔ)下實(shí)現(xiàn)頁面跳轉(zhuǎn),需要的朋友可以參考一下2021-11-11vue.js中proxyTable 轉(zhuǎn)發(fā)請求的實(shí)現(xiàn)方法
今天小編就為大家分享一篇vue.js中proxyTable 轉(zhuǎn)發(fā)請求的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09解決VUE mounted 鉤子函數(shù)執(zhí)行時(shí) img 未加載導(dǎo)致頁面布局的問題
這篇文章主要介紹了解決VUE mounted 鉤子函數(shù)執(zhí)行時(shí) img 未加載導(dǎo)致頁面布局的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07Vue element商品列表的增刪改功能實(shí)現(xiàn)
這篇文章主要介紹了Vue+element 商品列表、新增、編輯、刪除業(yè)務(wù)實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08vue路由跳轉(zhuǎn)攜帶參數(shù)的方式總結(jié)
我們知道在vue中每個(gè)頁面都需要在路由中聲明,下面這篇文章主要給大家介紹了關(guān)于vue路由跳轉(zhuǎn)攜帶參數(shù)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-10-10