Echarts 实现进度条效果

#Echarts 实现进度条效果
#效果图
效果图
#上代码

//Echarts 实现进度条效果
data = [
    {
        name: '服务订购数量',
        value: 6133,
    },
    {
        name: '服务订购人次',
        value: 23125,
    },
    {
        name: '微信推送户次',
        value: 43231,
    },
    {
        name: '微信推送条数',
        value: 15340,
    },
];
// 定义使用的颜色数组
const colors = ['blue', 'green', 'yellow ', 'red'];
getArrByKey = (data, k) => {
    let key = k || 'value';
    let res = [];
    if (data) {
        data.forEach(function (t) {
            res.push(t[key]);
        });
    }
    return res;
};
getSymbolData = (data) => {
    let arr = [];
    for (var i = 0; i < data.length; i++) {
        arr.push({
            value: data[i].value,
            symbolPosition: 'end',
        });
    }
    return arr;
};
opt = {
    index: 0,
};
color = ['blue', 'pink'];
data = data.sort((a, b) => {
    return b.value - a.value;
});
console.log(getSymbolData(data));
option = {
    backgroundColor: 'black',
    grid: {
        top: '2%',
        bottom: -15,
        right: 5,
        left: 5,
        containLabel: true,
    },
    xAxis: {
        show: false,
    },
    yAxis: [
        {
            triggerEvent: true,
            show: true,
            inverse: true,
            data: getArrByKey(data, 'name'),
            axisLine: {
                show: false,
            },
            splitLine: {
                show: false,
            },
            axisTick: {
                show: false,
            },
            axisLabel: {
                show: false,
                interval: 0,
                color: '#fff',
                align: 'left',
                margin: 80,
                fontSize: 13,
                formatter: function (value, index) {
                    return '{title|' + value + '}';
                },
                rich: {
                    title: {
                        width: 165,
                    },
                },
            },
        },
        {
            triggerEvent: true,
            show: true,
            inverse: true,
            data: getArrByKey(data, 'name'),
            axisLine: {
                show: false,
            },
            splitLine: {
                show: false,
            },
            axisTick: {
                show: false,
            },
            axisLabel: {
                interval: 0,
                shadowOffsetX: '20px',
                color: ['#fff'],
                align: 'right',
                verticalAlign: 'top',
                //lineHeight: -20,
                textStyle: {
                    color: '#fff', //坐标值得具体的颜色
                    padding: [-20, 0, 0, 0],
                    fontSize: 12,
                },
                fontSize: 12,
                formatter: function (value, index) {
                    return data[index].value;
                },
            },
        },
    ],
    series: [
        {
            name: '条',
            type: 'bar',
            showBackground: true,
            barBorderRadius: 30,
            yAxisIndex: 0,
            data: data,
            barWidth: 5,
            backgroundStyle: {
                color: 'pink',
            },
            itemStyle: {
                normal: {
                    barBorderRadius: 10,
                    color: function (params) {
                        return colors[params.dataIndex];
                        // 取每条数据的 index 对应 colors 中的 index 返回这个颜色
                    },
                },
                // color: 'pink',
                barBorderRadius: 4,
            },
            label: {
                normal: {
                    color: '#fff',
                    show: true,
                    position: [0, '-20px'],
                    textStyle: {
                        fontSize: 12,
                    },
                    formatter: function (a, b) {
                        return a.name;
                    },
                },
            },
        },
    ],
};

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员小挽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值