Echarts实现进度条效果

本文介绍了如何使用Echarts库创建一个动态的进度条效果。通过设置`xAxis`和`yAxis`的参数,隐藏坐标轴,并利用`barWidth`、`barMinHeight`和`LinearGradient`渐变色实现美观的条形效果。同时,通过`barGap`设置负值使两个条形重叠,展示进度变化。最后,通过`label`配置项添加内部标签,增强视觉反馈。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Echarts实现进度条效果

实现效果如图:
在这里插入图片描述

option = {
grid: {
                    containLabel: true,
                    left: 0,
                    right: 0,
                    top: 0,
                    bottom: 0,
                },
                xAxis: {
                    type: 'value',
                    splitLine: {
                        show: false
                    }, //坐标轴在 grid 区域中的分隔线
                    axisLabel: {
                        show: false
                    }, //坐标轴刻度标签
                    axisTick: {
                        show: false
                    }, //坐标轴刻度
                    axisLine: {
                        show: false
                    }, //坐标轴轴线
                },
                yAxis: {
                    type: 'category',
                    axisTick: {
                        show: false
                    },
                    axisLine: {
                        show: false
                    },
                    axisLabel: {
                        show: false
                    },
                },
                series: [{
                    type: "bar",
                    barWidth: 16,
                    barMinHeight: 20,
                    zlevel: 1,
                    data: [40],
                    itemStyle: {
                        normal: {
                            barBorderRadius: [0, 10, 10, 0],
                            color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
                                offset: 0.2,
                                color: '#359eff'
                            },
                                {
                                    offset: 1,
                                    color: "#35dbff"
                                }
                            ])
                        }
                    },

                }, {
                    type: "bar",
                    barGap: '-100%',
                    barWidth: 16,
                    data: [100],
                    itemStyle: {
                        normal: {
                            barBorderRadius: [0, 16, 16, 0],
                            color: new echarts.graphic.LinearGradient(
                                0, 0, 1, 0, [{
                                    offset: 0,
                                    color: 'rgba(75, 197, 253, 0)'
                                },
                                {
                                    offset: 1,
                                    color: 'rgba(75, 197, 253, 1)'
                                }
                            ]
                            ),
                            label: {
                                show: true,
                                position: 'insideRight',
                                formatter: '   ',
                                backgroundColor: '#94f6ff',
                                distance: 0,
                                borderColor: 'rgba(255, 255, 255, 0.5)',
                                borderWidth: 3,
                                borderRadius: 10,
                                color: '#94f6ff'
                            }
                        }
                    },

                }
                ],
};
### 如何使用 ECharts 实现多个圆环进度条效果 要通过 ECharts 创建多个圆环进度条,可以利用 `series` 中的 `type: 'gauge'` 或者更常见的 `type: 'pie'` 配置项来实现。以下是具体方法: #### 数据准备与配置 为了绘制多个圆环进度条,通常需要定义一组数据,每组数据对应一个圆环。可以通过设置不同的半径 (`radius`) 和位置 (`center`) 来调整各个圆环的位置和大小[^1]。 #### 示例代码 以下是一个完整的示例代码片段,展示如何创建三个不同颜色和百分比的圆环进度条: ```javascript option = { title: [ { text: 'Progress A', left: '20%', top: '85%' }, { text: 'Progress B', left: '50%', top: '85%' }, { text: 'Progress C', left: '80%', top: '85%' } ], series: [ { type: 'pie', radius: ['70%', '90%'], // 设置内外圈比例 center: ['20%', '50%'], // 圆心坐标 (水平, 垂直) labelLine: { show: false }, // 不显示标签线 label: { position: 'center', fontSize: 14 }, // 居中文字 data: [{ value: 60, name: 'A', itemStyle: { color: '#FFB3C5' } }] }, { type: 'pie', radius: ['70%', '90%'], center: ['50%', '50%'], labelLine: { show: false }, label: { position: 'center', fontSize: 14 }, data: [{ value: 80, name: 'B', itemStyle: { color: '#B3D4FF' } }] }, { type: 'pie', radius: ['70%', '90%'], center: ['80%', '50%'], labelLine: { show: false }, label: { position: 'center', fontSize: 14 }, data: [{ value: 40, name: 'C', itemStyle: { color: '#FFFFCC' } }] } ] }; ``` 上述代码展示了如何通过修改 `center` 参数将三个圆环分别放置在画布的不同区域,并设置了各自的颜色和数值[^2]。 #### 自定义样式 如果希望进一步美化图表,比如添加背景色、渐变填充或者动态动画效果,则可以在 `itemStyle` 中加入更多属性。例如,启用渐变填充如下所示: ```javascript data: [{ value: 60, name: 'A', itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: '#FFB3C5' }, { offset: 1, color: '#FFFFFF' } ]) } }] ``` 此部分实现了从指定起始颜色到结束颜色的平滑过渡[^3]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值