基于vue3+antDesign2+echarts?實(shí)現(xiàn)雷達(dá)圖效果
右上角時間選擇器的實(shí)現(xiàn)
- 修改ant組件樣式
根據(jù)原型圖,該選擇器為月份時間選擇器,使用a-month-picker,但原始的月份選擇器樣式與設(shè)計(jì)圖不符,需要進(jìn)行修改,修改有分為兩部分:1.選擇框;2.額外彈出的日歷
- 選擇框樣式修改
修改ant組件時應(yīng)避免全局修改,如使用less語法,對ant組件的修改應(yīng)在該頁面的class下
<style lang="less" > @vw: 19.2vw; @vh: 10.8vh; .ping_index { .ant-picker { border: none; height: 28 / @vh; font-size: 14 / @vw; //修改字體居中 .ant-picker-input > input { text-align: center; color: rgba(255, 255, 255, 0.8); } //修改右側(cè)下拉圖標(biāo) .anticon svg { color: rgb(143, 135, 135); } } </style>
- 額外彈出的日歷
額外彈出的日歷框是在#app之外的,故無法與選擇框使用相同方法進(jìn)行修改,需要利用dropdownClassName屬性來修改樣式
a-month-picker( ... dropdownClassName="month_class" ) <style lang="less"> .month_class { .ant-picker-panel-container { background-color: #010a21; border: none; .ant-picker-panel { background: linear-gradient(0deg, rgba(0, 0, 0, 0), rgba(222, 60, 70, 0)); box-shadow: 0 0 10 / @vh 0 #005088 inset; .ant-picker-header button { color: rgba(255, 255, 255, 0.8); } .ant-picker-cell-in-view { color: rgba(255, 255, 255, 0.8); } .ant-picker-cell-selected { background: rgba(28, 68, 169, 0.7); } .ant-picker-cell-in-view:hover { background: rgba(28, 68, 169, 0.6); box-shadow: 0 0 18 / @vh 0 #1c44a9 inset; } .ant-picker-cell:hover { background-color: transparent; } .ant-picker-cell-inner { background: transparent !important; } } } } </style>
- 數(shù)據(jù)綁定
- 默認(rèn)時間
設(shè)置默認(rèn)事件時需要對時間格式進(jìn)行確定,根據(jù)原型圖需要的時年-月的格式,故需要將ant組件的valueFormat設(shè)置為“YYYY-MM”
綁定的值也需要利用moment.js處理得到相同是時間格式
a-month-picker.info_btn( v-model:value="selectedMonth", value-format="YYYY-MM" ) let selectedMonth = ref(moment(new Date()).format("YYYY-MM"));
- 時間改變時觸發(fā)的事件
利用@change綁定事件,考慮到接口需要分別傳輸年、月,需要對selectedMonth進(jìn)行切割
a-month-picker.info_btn( v-model:value="selectedMonth", value-format="YYYY-MM" @change="changeMonth()" ) let changeMonth = () => { let year = selectedMonth.value.substring(0,4) let month = Number(selectedMonth.value.substring(5,7)) //封裝過的接口 getSafetyIndex({ year, month }).then(( res ) => { console.log(res); }) }
五角雷達(dá)圖的繪制及數(shù)據(jù)渲染
接口返回的數(shù)據(jù)是類別名稱的縮寫,為了使得數(shù)據(jù)和類別在渲染時能夠?qū)?yīng),在定義雷達(dá)圖indicator時添加了index字段,用于遍歷接口數(shù)據(jù)得到與indicator中順序相同的數(shù)據(jù)數(shù)組
let indecatorList = [ { name: "火災(zāi)情況", max: 10, index: 'hjqk', }, { name: "交通安全", max: 10, index: 'jtaq', }, { name: "信訪形勢", max: 10, index: 'xfxs', }, { name: "反電詐", max: 10, index: 'fdz', }, { name: "矛盾糾紛", max: 10, index: 'mdjf', }, ]; let getData = ( data ) => { let series = [] indecatorList.map(( item ) => { series.push(data[item.index]) }) setOptions(series); }; let setOptions = ( seriesData = [0,0,0,0,0] ) => { let option = { radar: { ... indicator: indecatorList, }, ... series: [ ... { type: "radar", data: [ { value: seriesData, }, ], }, ], }; chart.setOption(option); };
到此這篇關(guān)于基于vue3+antDesign2+echarts 實(shí)現(xiàn)雷達(dá)圖的文章就介紹到這了,更多相關(guān)vue3 echarts雷達(dá)圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue實(shí)現(xiàn)虛擬滾動渲染成千上萬條數(shù)據(jù)
本文主要介紹了vue實(shí)現(xiàn)虛擬滾動渲染成千上萬條數(shù)據(jù),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02Vite中自制mock服務(wù)器(不使用第三方服務(wù))
本文主要介紹了Vite中自制mock服務(wù)器,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04Vue 頁面權(quán)限控制和登陸驗(yàn)證功能的實(shí)例代碼
這篇文章主要介紹了Vue 頁面權(quán)限控制和登陸驗(yàn)證功能的實(shí)例代碼,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-06-06Vue項(xiàng)目中引入外部文件的方法(css、js、less)
本篇文章主要介紹了Vue項(xiàng)目中引入外部文件的方法(css、js、less),非常具有實(shí)用價值,需要的朋友可以參考下2017-07-07Vue3中使用reactive時,后端有返回?cái)?shù)據(jù)但dom沒有更新的解決
這篇文章主要介紹了Vue3中使用reactive時,后端有返回?cái)?shù)據(jù)但dom沒有更新的解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03