echarts 按钮与多图表联动

html 部分

 <div v-for="d in abnormalColors" :key="d.name"
                     style="cursor: pointer"
                         @click="handleToggleSelected(d.name, d.state);d.state = !d.state">
                  <div class="colorIcon" :style="'background-color:' + (d.state ? d.color : '#cccccc')"></div>
                  <span v-text="d.name" />
                </div>
<div class="break-content" ref="breakChart">
                    <div :id="`breakChart${index}`" :key="item.id" v-for="(item, index) in abnormalReason"></div>
                </div>

vue 部分

private setAbnormalData() {
        this.abnormalReason.forEach((item: any, index: number) => {

            this.abnormalChart(`breakChart${index}`, item)
        })
    }
    // 异常终止原因:调用6遍
    private abnormalChart(id: any, obj: any) {
        var color=['#ff5b00','#00ffff','#0457bb','#ffa800',
            '#ffe000','#00cfff','#ff3000']
        var data: any = []
        obj.numberDTOList.forEach((item: any, i: any) => {
            if(!this.abnormalColorsObj[item.name]) {
                this.abnormalColors.push({
                    name: item.name,
                    color: color[i],
                    state: true
                })
                this.abnormalColorsObj[item.name] = color[i]
            }
            data.push(
                {
                    value: item.number,
                    name: item.name,
                    itemStyle: {
                        normal: {
                            borderWidth: 5,
                            shadowBlur: 20,
                            borderColor:color[i],
                            shadowColor: color[i]
                        }
                    }
                }
            )
        })
        // 异常终止原因-配置项
        const option: any = {
            title: {
                text: obj.name + '\n\n' + obj.number,
                top: '37%',
                textAlign: "center",
                left: "48%",
                textStyle: {
                    color: '#fff',
                    fontSize: 15,
                    fontWeight: 700
                }
            },
            legend: {
                show: false,
                icon: 'circle',
                itemWidth: 10,
                textStyle: {
                    color: '#fff',
                    fontSize: 11,
                }
            },
            clockWise: false,
            radius: [50, 50],
            tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b}: {c} ({d}%)'
            },
            graphic: {
                elements: [{
                    type: "image",
                    z: 3,
                    style: {
                        image: require('../../assets/img/backImg.png'),
                        width: 65,
                        height: 65
                    },
                    left: 'center',
                    top:  'center',
                    position: [100, 100]
                }]
            },
            series: [
                {
                    name: obj.name,
                    type: 'pie',
                    hoverAnimation: false,
                    left: '35px',
                    right: '35px',
                    label: {
                        normal: {
                            show: true,
                            formatter: '{d}%',
                            textStyle: {
                                align: 'center',
                                baseline: 'middle',
                                fontSize: 12
                            }
                        }
                    },
                    labelLine: {
                        show: false,
                        length: 2,
                        length2: 5
                    },
                    itemStyle: {
                        normal: {
                            borderWidth: 1,
                            shadowBlur: 20,
                        }
                    },
                    radius: ['80%', '80%'],
                    data: data,
                }
            ]
        };
        const breakChart: any = document.getElementById(id)
        let chart = echarts.init(breakChart)
        chart.setOption(option)
        this.AbnormalTerminationReasonChart.push(chart)
        window.addEventListener('resize', this.resizeHandle)
    }

    // 切换选中状态(使用官方event事件进行联动)
    private handleToggleSelected(name: string, state: boolean) {
        this.AbnormalTerminationReasonChart.map((item: any) => {
            item.dispatchAction({
                type: state ? 'legendUnSelect' : 'legendSelect',    // legendUnSelect取消选中 legendSelect选中
                name
            })
        })
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值