欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > vue+ echarts 实现图表标题自定义

vue+ echarts 实现图表标题自定义

2026/5/2 15:42:17 来源:https://blog.csdn.net/w_jiunian/article/details/148559909  浏览:    关键词:vue+ echarts 实现图表标题自定义

图表标题自定义部分代码:

 title: {text: `{a|${sum}}\n{b|总数}`,subtext: `{a|${num}} {trendIcon|}  {c|较上月}`,textAlign: 'center',left: '32%',top: '32%',textStyle: {rich: {a: {fontFamily: 'DINPro, DINPro',fontWight: 'bold',fontSize: 36,color: '#0FA674',lineHeight: 46},b: {fontFamily: 'Source Han Sans CN, Source Han Sans CN',fontWeight: '500',fontSize: 16,color: '#212121',lineHeight: 24,marginTop: 8,marginBottom: 8},}},subtextStyle: {rich: {a: {fontFamily: 'Source Han Sans CN, Source Han Sans CN',fontWeight: '500',fontSize: 14,color: '#FF8484',lineHeight: 24},trendIcon: {backgroundColor: {image: type == 'up' ? arrowUp : arrowDw},},c: {fontFamily: 'Source Han Sans CN, Source Han Sans CN',fontWeight: '500',fontSize: 14,color: '#999999',lineHeight: 24}}},},

标题中的三角符号,我是直接用的图片,这块有一个判断,上升箭头向上,下降反之。之前打算引用一张图片,使用  transform: rotate(180deg); 但是没用,后面我就引用了两张图

全部代码:

<!--物种等级-->
<template><div id="chartSpeciesDom" ref="chartSpeciesContent" class="charts-content"></div>
</template>
<script lang="ts" setup>
// 图片
import arrowUp from '@/assets/images/wildlife/dashboard/arrow_up.png';
import arrowDw from '@/assets/images/wildlife/dashboard/arrow_dw.png';
//echarts
import * as echarts from 'echarts';//静态文件
import theme from "@/assets/echarts/dark.json";
// 初始化
onMounted(()=>{initChart()getChart()
})
/*** 图表*/
type EChartsOption = echarts.EChartsOption;
let chartSpeciesDom
let chartSpecies
function initChart() {echarts.registerTheme('dark', theme);chartSpeciesDom = document.getElementById('chartSpeciesDom')!;chartSpecies = echarts.init(chartSpeciesDom, 'dark');
}
let option;
function getChart() {let values = [110,56,50,30,50];let sum = values[0] + values[1] + values[2] + values[3] + values[4] ;let legendData = ["平安巡防岗", "垃圾分类员", "交通督导员", "场景引导员", "爱心助学岗"];let colorList = ['#EF0C2B', '#F0D160', '#00C17B', '#63CCE1', '#4A94FF'];let num = '39.9%';let type = 'up'option = {title: {text: `{a|${sum}}\n{b|总数}`,subtext: `{a|${num}} {trendIcon|}  {c|较上月}`,textAlign: 'center',left: '32%',top: '32%',textStyle: {rich: {a: {fontFamily: 'DINPro, DINPro',fontWight: 'bold',fontSize: 36,color: '#0FA674',lineHeight: 46},b: {fontFamily: 'Source Han Sans CN, Source Han Sans CN',fontWeight: '500',fontSize: 16,color: '#212121',lineHeight: 24,marginTop: 8,marginBottom: 8},}},subtextStyle: {rich: {a: {fontFamily: 'Source Han Sans CN, Source Han Sans CN',fontWeight: '500',fontSize: 14,color: '#FF8484',lineHeight: 24},trendIcon: {backgroundColor: {image: type == 'up' ? arrowUp : arrowDw},},c: {fontFamily: 'Source Han Sans CN, Source Han Sans CN',fontWeight: '500',fontSize: 14,color: '#999999',lineHeight: 24}}},},tooltip: {trigger: 'item',borderColor: 'rgba(255,255,255,.3)',backgroundColor: 'rgba(13,5,30,.6)',borderWidth: 1,padding: 5,textStyle:{color:'#fff'}},legend: {type: "scroll",orient: 'vertical',right: '5%',align: 'auto',top: 'middle',itemWidth: 10,itemHeight: 10,textStyle: {fontSize:14,color: '#212121',lineHeight: 32},data: legendData},series: [{type: 'pie',left: '16%',center: ['20%', '45%'],radius: ['45%', '65%'],clockwise: true,avoidLabelOverlap: true,hoverOffset: 15,itemStyle: {normal: {color: function(params) {return colorList[params.dataIndex]}}},label: {show: false},data: [{name:legendData[0],value:values[0]},{name:legendData[1],value:values[1]},{name:legendData[2],value:values[2]},{name:legendData[3],value:values[3]},{name:legendData[4],value:values[4]}]}]};option && chartSpecies.setOption(option);
}
</script>
<style lang="scss" scoped>
.charts-content{width: 100%;height: 100%;
}
</style>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词