vue實(shí)現(xiàn)表格動(dòng)態(tài)嵌入折線圖的繪制代碼
demo效果:
這里的折線是使用g6圖表繪制antv/g6
- 首先下載 npm install @antv/g6 --save
- 然后給需要畫(huà)線的盒子一個(gè)id,以便獲取
- 還要計(jì)算出這個(gè)canvas盒子在表格的位置
- 然后根據(jù)表格數(shù)據(jù)的length來(lái)生成點(diǎn)位
- 然后最后用g6把點(diǎn)位連接起來(lái)
完整代碼``
<div style="width: 100%"> <div class="table-img weidu"> <div class="cnavasbox" id="cnavasbox" :style="{ height: `${canvasHeight}px` }"></div> <el-table :highlight-current-row="false" :data="tableData" style="width: 1091px" class="custom-table" :header-cell-style="headerCellStyle"> <el-table-column prop="targetName" label="維度" width="126px" /> <el-table-column prop="lowRemark" label="低分表現(xiàn)" width="205px"> <template #default="scope"> <div v-for="(item, index) in scope.row.lowRemark" :key="index" class="redcirclebox"> <div class="redcircle"></div> <div class="redtitle">{{ item }}</div> </div> </template> </el-table-column> <el-table-column label="低分"> <el-table-column label="10" width="46px"></el-table-column> <el-table-column label="20" width="46px"></el-table-column> <el-table-column label="30" width="46px"></el-table-column> <el-table-column label="40" width="46px"></el-table-column> </el-table-column> <el-table-column label="中分"> <el-table-column label="50" width="46px"></el-table-column> <el-table-column label="60" width="46px"></el-table-column> <el-table-column label="70" width="46px"></el-table-column> </el-table-column> <el-table-column label="高分"> <el-table-column label="80" width="46px"></el-table-column> <el-table-column label="90" width="46px"></el-table-column> <el-table-column label="100" width="62px"></el-table-column> </el-table-column> <el-table-column prop="tallRemark" label="高分表現(xiàn)" width="205px"> <template #default="scope"> <div v-for="(item, index) in scope.row.tallRemark" :key="index" class="redcirclebox"> <div class="redcircle greencircle"></div> <div class="greentitle">{{ item }}</div> </div> </template> </el-table-column> <el-table-column prop="score" label="分?jǐn)?shù)" width="79px" /> </el-table> </div> </div>
js部分
const headerCellStyle = ref({ backgroundColor: '#ADC3E4 !important', color: '#1A1A1A', fontWeight: '500', fontSize: '26PX', textAlign: 'center', fontFamily: 'SourceHanSans', paddingLeft: '0px', paddingRight: '0px', height: '51px', }) previewPdfBasic({ id: id }).then(res => { tableData.value = res tableData.value.forEach((item, index) => { item.id = index }) dimensionatableData.value = res console.log(res, 'ressssssssssss') setTimeout(() => { const bb = document.querySelector('.el-table__body-wrapper') console.log(bb, '獲取盒子1111111111') canvasHeight.value = bb.offsetHeight console.log(bb.offsetHeight) const canvas = document.querySelector('.cnavasbox') graphConfig.container = canvas graphConfig.width = canvas.offsetWidth graphConfig.height = bb.offsetHeight const rowsArr = document.querySelectorAll('.weidu .el-table__row') const rowArrHeight = [] rowsArr.forEach(item => { rowArrHeight.push(item.offsetHeight) }) console.log(rowArrHeight, 'rowArrHeight') tableData.value.forEach((item, index) => { if (item.score <= 90) { data.value.nodes[index] = { x: (item.score / 90) * 414, id: `dot${index}`, y: rowArrHeight.slice(0, index).reduce((total, num) => total + num, 0) + rowArrHeight[index] / 2, } } else { data.value.nodes[index] = { x: 414 + (item.score / 10) * 62, id: `dot${index}`, y: rowArrHeight.slice(0, index).reduce((total, num) => total + num, 0) + rowArrHeight[index] / 2, } } }) data.value.nodes.forEach((item, index) => { if (index < data.value.nodes.length - 1) { data.value.edges.push({ source: data.value.nodes[index].id, target: data.value.nodes[index + 1].id, }) } }) console.log(rowsArr, 'rowsArr') const graph = new G6.Graph(graphConfig) graph.data(data.value) graph.render() }) })
到此這篇關(guān)于vue實(shí)現(xiàn)表格動(dòng)態(tài)嵌入折線圖的繪制代碼的文章就介紹到這了,更多相關(guān)vue表格動(dòng)態(tài)嵌入折線圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解vue 路由跳轉(zhuǎn)四種方式 (帶參數(shù))
這篇文章主要介紹了vue 路由跳轉(zhuǎn)四種方式 (帶參數(shù)),本文通過(guò)實(shí)例代碼給大家介紹的詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-04-04Vue中el-tree樹(shù)全部展開(kāi)或收起的實(shí)現(xiàn)示例
本文主要介紹了Vue中el-tree樹(shù)全部展開(kāi)或收起的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07element-ui 表格數(shù)據(jù)時(shí)間格式化的方法
這篇文章主要介紹了element-ui 表格數(shù)據(jù)時(shí)間格式化的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08vue路由切換時(shí)取消之前的所有請(qǐng)求操作
這篇文章主要介紹了vue路由切換時(shí)取消之前的所有請(qǐng)求操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09Vue-Access-Control 前端用戶權(quán)限控制解決方案
Vue-Access-Control是一套基于Vue/Vue-Router/axios 實(shí)現(xiàn)的前端用戶權(quán)限控制解決方案。這篇文章主要介紹了Vue-Access-Control:前端用戶權(quán)限控制解決方案,需要的朋友可以參考下2017-12-12vue3 實(shí)現(xiàn)牙位圖選擇器的實(shí)例代碼
這篇文章主要介紹了vue3 實(shí)現(xiàn)牙位圖選擇器的實(shí)例代碼,代碼簡(jiǎn)單易懂,需要的朋友參考下吧2025-04-04