vue使用echart自定義標簽以及顏色
本文實例為大家分享了vue使用echart自定義標簽以及顏色的具體代碼,供大家參考,具體內(nèi)容如下
常規(guī)樣式
UI畫的樣式效果
細節(jié)在于這個小圓點的顏色要和餅圖塊的顏色一致,這在5.0(echarts版本)之前的版本是可以使用這一段代碼實現(xiàn)的。
label:{ formatter: params => {//● return ( '{icon|▅}{name|' +params.name+ '}{value|' + params.value + '}' ); }, rich: { icon: { fontSize: 16 }, name: { fontSize: 16, padding: [0, 10, 0, 4], }, value: { fontSize: 16, } }, }
但是由我的項目里面有需要用到5.0才支持的一些特效,不得已升級到5.0,那這個顏色就不起效了。就需要找個方案實現(xiàn)他,最后是這樣實現(xiàn)的。在數(shù)據(jù)賦值的時候給每個label標簽的顏色進行重新賦值,去餅圖色塊的值進行賦值。
這里面兩份數(shù)據(jù),是因為在里面疊加了餅圖內(nèi)部的百分比,就是籃框圈住的東西
配置項:
series: [ { type: 'pie', radius: [0, '75%'], center: ['50%', '50%'], top:0, // roseType: 'radius', avoidLabelOverlap: true, // minShowLabelAngle:0.6, startAngle: 0, label: { show:true, position: 'outer', alignTo: 'edge', //另一種方案的點 normal: { formatter: params => { // formatColor(params.color) // color = params.color return ( '{icon|● }{name|' + params.name + '}'+'\n'+'{value|' + params.value+'次' + '}' ); }, padding:[0,-40,25,-40], rich: { icon: { fontSize: 15, }, name: { fontSize: 13, color: '#666666' }, value: { fontSize: 12, color: 'rgba(0,0,0,0.35)' } } } }, labelLine:{ length:10, length2:70, smooth: false, lineStyle:{ color:"rgba(0,0,0,0.15)" } }, data: [] }, { name: '', type: 'pie', radius: [0, '75%'], center: ['50%', '50%'], data:[], top:0, // roseType: 'radius', avoidLabelOverlap: true, startAngle: 0, itemStyle: { normal: { label: { show: true, position: 'inner', color:"#fff", fontSize: 14, align:"center", formatter: function (p) { //指示線對應文字,百分比 return p.percent + "%"; } }, } } } ]
重新賦值:
//拿到色卡 重新賦值 let colorArr = pieOption.color let seriesData = JSON.parse(JSON.stringify(this.orderServiceTimeLenData.output.value.rows))||[] let seriesData1 = JSON.parse(JSON.stringify(this.orderServiceTimeLenData.output.value.rows))||[] if(seriesData.length){ seriesData.forEach((item,index)=>{ item.name = item.typeStr item.value = item.num item.label = {color:colorArr[index]} }) seriesData1.forEach((item,index)=>{ item.name = item.typeStr item.value = item.num }) } return {legend: {data: seriesData}, series: [{data: seriesData},{data: seriesData1}]};
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
?用Vue?Demi?構(gòu)建同時兼容Vue2與Vue3組件庫
這篇文章主要介紹了?用Vue?Demi?構(gòu)建同時兼容Vue2與Vue3組件庫,我們通過考慮其功能、工作原理以及如何開始使用它來了解?Vue?Demi,下面我們一起進入文章學起來吧2022-02-02Vue 報錯TypeError: this.$set is not a function 的解決方法
這篇文章主要介紹了Vue 報錯TypeError: this.$set is not a function 的解決方法,分享給大家,需要的朋友們下面隨著小編來一起學習學習吧2018-12-12el-select選擇器組件下拉框增加自定義按鈕的實現(xiàn)
本文主要介紹了el-select選擇器組件下拉框增加自定義按鈕的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2024-07-07在Vue中使用動態(tài)import()語法動態(tài)加載組件
在Vue中,你可以使用動態(tài)import()語法來動態(tài)加載組件,動態(tài)導入允許你在需要時異步加載組件,這樣可以提高應用程序的初始加載性能,本文給大家介紹在Vue中使用動態(tài)import()語法動態(tài)加載組件,感興趣的朋友一起看看吧2023-11-11