echarts 排名

 

//柱形图 产品数量
        getProductCount() {
            let cateList = []
            let cateNumList = []
            let totalList=[]
            this.saleCount = 0
            api.groupcatebyarea().then(res => {
                console.log(res)
                totalList=res
                totalList.sort(utils.compare('num'))
                totalList.forEach(item => {
                    this.saleCount += item.num

                    cateList.unshift(item.name)
                    cateNumList.unshift(item.num)
                })

                const myChart = this.$echarts.init(
                    document.getElementById("productcount-data-chart")
                );
                let rankIcons = [
                    require('@/assets/img/rank1.png'),
                    require('@/assets/img/rank2.png'),
                    require('@/assets/img/rank3.png'),
                    require('@/assets/img/rank4.png'),
                ]
                let ydata = cateList
                var option = {
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'shadow'
                        }
                    },
                    grid: {
                        x: '90%',
                        y: '100%',
                        x2: '70%',
                        y2: '100%',
                    },
                    xAxis: {
                        show: true,
                        type: 'value',
                        splitLine: {
                            show: false
                        },
                        axisLine: {     //x轴坐标轴
                            show: false
                        },
                        axisLabel: {
                            show: false
                        },
                        axisTick: {		//x轴刻度线
                            show: false
                        },
                    },
                    yAxis: {
                        type: 'category',
                        data: ydata,
                        // boundaryGap: [0.2, 0.2],
                        axisLabel: {
                            margin: 120,
                            align: "left",
                            formatter: function (value, index) {
                                let ind = index + 1;
                                if (ind == ydata.length) {
                                    return "{one|" + (ydata.length - index) + "} {a|" + value + "}";
                                } else if (ind + 1 == ydata.length) {
                                    return "{two|" + (ydata.length - index) + "} {b|" + value + "}";
                                } else if (ind + 2 == ydata.length) {
                                    return (
                                        "{three|" + (ydata.length - index) + "} {c|" + value + "}"
                                    );
                                }
                                if (ydata.length - index > 9) {
                                    return (
                                        "{five|" + (ydata.length - index) + "} {d|" + value + "}"
                                    );
                                }
                                return "{four|" + (ydata.length - index) + "} {d|" + value + "}";
                            },
                            rich: {
                                a: {
                                    color: "#fff",
                                },
                                b: {
                                    color: "#fff",
                                },
                                c: {
                                    color: "#fff",
                                },
                                d: {
                                    color: "#fff",
                                },
                                // 第一名
                                one: {
                                    color: "white",
                                    width: 20,
                                    height: 16,
                                    backgroundColor: { image: rankIcons[0] },
                                    fontSize: 11,
                                    align: 'center'
                                },
                                // 第二名
                                two: {
                                    color: "white",
                                    width: 20,
                                    height: 16,
                                    backgroundColor: { image: rankIcons[1] },
                                    fontSize: 11,
                                    align: 'center'
                                },
                                // 第三名
                                three: {
                                    color: "white",
                                    width: 20,
                                    height: 16,
                                    backgroundColor: { image: rankIcons[2] },
                                    fontSize: 11,
                                    align: 'center'
                                },
                                // 一位数
                                four: {
                                    color: "white",
                                    width: 20,
                                    height: 16,
                                    backgroundColor: { image: rankIcons[3] },
                                    fontSize: 11,
                                    align: 'center'
                                },
                                // 两位数
                                five: {
                                    color: "white",
                                    width: 20,
                                    height: 16,
                                    backgroundColor: { image: rankIcons[3] },
                                    fontSize: 11,
                                    align: 'center'

                                }
                            },
                        },
                        axisLine: {
                            show: false
                        },
                        axisTick: {
                            show: false,
                            alignWithLabel: true,
                        },
                        splitArea: { show: false },
                    },
                    series: [{
                        data: cateNumList,//假数据
                        type: 'bar',
                        showBackground: true,
                        backgroundStyle: {
                            color: '#0A337E',
                            borderRadius: 100,
                        },
                        barWidth: 6,//柱图宽度
                        itemStyle: {
                            normal: {
                                barBorderRadius: 10,
                                label: {
                                    show: true,	//是否展示
                                    position: ['280', '0'], //在上方显示
                                    textStyle: {	//数值样式,显示的文字大小和颜色
                                        fontSize: '10',
                                        color: '#fff'
                                    }
                                },

                                color: '#069DFD' //蓝色
                            }
                        },
                    }]
                };
                myChart.setOption(option);
                window.addEventListener("resize", function () {
                    myChart.resize();
                });
            })


        },

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值