Vue+iview在Modal中使用 ECharts 柱状图(二)

Vue+iview在Modal中使用 ECharts 柱状图(二)


针对项目需求解决ECharts的不足点:
柱条对应数据量差距太大,使得数据量低的柱条点击不方便

loadCharts() {
    let myChart = E.init(this.$refs.chart);
    myChart.setOption({
        color: ["#3398DB"],
        tooltip: {                  // 坐标轴指示器,坐标轴触发有效
            trigger: "axis",
            axisPointer: {
                type: "shadow"      // 默认是直线line,更改为阴影
            }
        },
        grid: {
            left: "3%",
            right: "4%",
            bottom: "3%",
            containLabel: true
        },
        xAxis: [
            {
                type: "category",
                data: this.xAxisName,
                axisTick: {
                    alignWithLabel: true
                },
                axisLine: {
                    lineStyle: {
                        color: "#fff"
                    }
                },
                axisLabel: {
                    interval: 0,
                    rotate: "45"
                }
            }
        ],
        yAxis: [
            {
                type: "value",
                splitLine: {
                    show: false
                },
                axisLine: {
                    lineStyle: {
                        color: "#fff"
                    }
                }
            }
        ],
        series: [
            {
                name: "数量",
                type: "bar",
                barWidth: "10",
                data: this.serCount,
                itemStyle: {
                    normal: {
                        label: {
                            show: true,
                            position: "top"
                        }
                    }
                }
            }
        ]
    });
    // 非图标区可点击事件
    myChart.getZr().on("click", params => {
        const pointInPixel = [params.offsetX, params.offsetY];
        if (myChart.containPixel("grid", pointInPixel)) {
            let xIndex = myChart.convertFromPixel(
                { seriesIndex: 0 }, [params.offsetX, params.offsetY]
            )[0];
            xIndex = Math.abs(xIndex);
            let count = myChart.getOption().series[0].data[xIndex];

            if (count != 0) {
                let item = JSON.parse(this.tempReport.tabs);
                let name = myChart.getOption().xAxis[0].data[xIndex];
                this.elseContent = null;
                $.each(item, (i, d) => {
                    if (name == d.name) this.elseContent = d.data;
                });
                this.elseTitle = name;
                this.echartShow = false;
                this.elseShow = true;
            }
        }
    });
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值