echarts饼图选中,默认、鼠标移入移出、点击选中

选中效果:

    //let apiCounterDom = document.getElementById('main');
    //this.apiCounterChart = this.$echarts.init(apiCounterDom);
    //this.apiCounterChart.setOption(this.apiCounterOption);
    //this.pieClick(this.apiCounterChart)

    pieChartSel(charts) {
        const that = this;
        let index = 0;
        //默认选中
        charts.dispatchAction({
            type: 'highlight',
            seriesIndex: 0,
            dataIndex: 0,
        });

        //hover选中
         charts.on('mouseover', function(e) {
             if (e.dataIndex != index) {
                 charts.dispatchAction({
                     type: 'downplay',
                     seriesIndex: 0,
                    dataIndex: index,
                 });
             }
         });
         charts.on('mouseout', function(e) {
             index = e.dataIndex;
             charts.dispatchAction({
              type: 'highlight',
                 seriesIndex: 0,
                 dataIndex: e.dataIndex,
             });
         });

        //点击选中
        charts.on("click", function(e) {
            if (e.dataIndex != index) {
                charts.dispatchAction({
                    type: 'downplay',
                    seriesIndex: 0,
                    dataIndex: index,
                });
            }
            index = e.dataIndex;
            charts.dispatchAction({
                type: 'highlight',
                seriesIndex: 0,
                dataIndex: e.dataIndex,
            });
        });

    }

猜你喜欢

转载自blog.csdn.net/m0_66722601/article/details/128811880