当前位置: 首页 > news >正文

vue3中实现渐变三层柱状图

效果:

假数据标注在代码里,自行放开查看效果

组件 barEchart.vue

<script setup>
import { ref } from 'vue';
import * as echarts from 'echarts';const props = defineProps({id: {type: String,default: ''},width: {type: String,default: '100%'},height: {type: String,default: '230px'},data: {type: Array,default: () => {}}
})
// 生成渐变色
const basicColors = [['#F76866 ', 'rgba(247, 104, 102, 0.4)'],['#FEA73B ', 'rgba(254, 167, 59, 0.4)'],['#4E82FB ', 'rgba(78, 130, 251, 0.4)'],
]
function genLinearGradient(colors) {let color = {type: 'linear',x: 0,y: 0,x2: 0,y2: 1,colorStops: [{offset: 0,color: colors[0] // 0%处的颜色},{offset: 1,color: colors[1] // 100%处的颜色}],global: false}return color;
}
const option = ref({grid: {left: '5%',right: '1%',bottom: '3%',top: '15%',containLabel: true},tooltip: {trigger: 'axis',show: true},xAxis: {type: 'category',data: [],axisLabel: {//坐标轴字体颜色textStyle: {color: '#8C8C8C'}},axisLine: {lineStyle: {color: '#e5e5e5'}},axisTick: {//y轴刻度线show: false},splitLine: {//网格show: false}},yAxis: {type: 'value',boundaryGap: ['0%', '20%'],name: "单位/卡",axisLabel: {//坐标轴字体颜色textStyle: {color: 'rgb(0,0,0,0.6)'}},axisLine: {show: false},axisTick: {//y轴刻度线show: false},splitLine: {//网格show: true,lineStyle: {color: '#dadde4',}}},series: [{type: 'bar',name: '',stack: 'sum',color: '#00BFBC',barMaxWidth: '20%', //柱子宽度itemStyle: {color: genLinearGradient(basicColors[2]),},data: []},{type: 'bar',name: '',stack: 'sum',color: '#00BFBC',barMaxWidth: '20%', //柱子宽度itemStyle: {color: genLinearGradient(basicColors[1]),},data: []},{type: 'bar',name: '',stack: 'sum',barMaxWidth: '20%', //柱子宽度itemStyle: {color: genLinearGradient(basicColors[0]),},data: []},]
})
const initChart = () => {const chartDom = document.getElementById(props.id);if (!chartDom) return;const myChart = echarts.init(chartDom);option.value.xAxis.data = props.data.row //["人事","财务","维护","合同","采购","建设","订单"]// [//    { value: 45, name: "华为", icon: 'icon_hw.png' },//    { value: 40, name: "电信", icon: 'icon_dx.png' },//    { value: 35, name: "联通", icon: 'icon_lt.png' },//]option.value.series[0].data = props.data.series[0].dataoption.value.series[1].data = props.data.series[1].dataoption.value.series[2].data = props.data.series[2].dataoption.value.series[0].name = props.data.series[0].nameoption.value.series[1].name = props.data.series[1].nameoption.value.series[2].name = props.data.series[2].namemyChart.setOption(option.value);// 响应式调整window.addEventListener('resize', function () {myChart.resize();});
};
watch(() => props.data, (data) => {if (Object.keys(data).length === 0) returninitChart()
},{immediate: true})
</script><template><div><div :id="props.id" :style="{ width: props.width, height: props.height }"></div></div>
</template><style scoped lang=scss></style>

在页面中直接引入即可

http://www.dtcms.com/a/519869.html

相关文章:

  • 7.IXM6U系统时钟
  • 算子相关通用概念整理
  • Java 操作 PDF 图像:轻松驾驭 PDF 文档中的图片
  • OS_2 进程与线程(进程管理)
  • 网站规划 评价谷歌三件套一键安装
  • 腾讯云服务器如何建设网站百度关键词排名突然没了
  • 【论文笔记】LTX-Video极致速度的视频生成模型
  • 安科瑞防逆流解决方案:物联网技术赋能光伏能源高效管理
  • 如何根据不同的场景选择YOLO相应的基座模型
  • 【OJ】二叉树的经典OJ题
  • Excel 重磅更新 AI技术走进公式
  • div嵌套影响网站收录建设公司需要网站吗
  • VBA技术资料MF383:处理Excel中存储为文本的数据
  • 注册网站的公司名字网站项目建设流程图
  • 大数据存储组件分别位于数据仓库的哪一层
  • Dubbo应用开发之RPC直连开发
  • 坦电容做电源滤波,放在陶瓷电容的前面还是后面好
  • 北京城建亚泰建设集团有限公司网站首页wordpress中文教程 下载
  • 虚幻引擎5 GAS开发俯视角RPG游戏 P06-13 属性菜单 - 边框值
  • Bash 括号:()、{}、[]、$()、$(() )、${}、[[]] 到底有什么区别?
  • bash执行脚本 CondaError: Run ‘conda init‘ before ‘conda activate‘
  • 虚幻引擎5 GAS开发俯视角RPG游戏 P06-11 初始化生命值和法力值属性
  • 做家政网站网络公司基础建设
  • 比特币白皮书
  • 网站速度诊断 慢坚持以高质量发展为首要任务戈
  • 苹果 T2 芯片如何影响 Mac 数据恢复
  • Open XR 手势控制模块开发。Monado 自定义手势识别模型 基于UltraLeap python实现
  • SQL Server ODBC 数据源配置指南(本地 + 远程,附实操细节)
  • 惠普电脑VT虚拟化技术开启指南:新旧BIOS设置全解析
  • SQL NULL 值