在vue中 echarts 餅圖 legend 取消點擊事件

取消點擊事件兩種方法:

  1. legend: {selectedMode:false,}//取消圖例上的點擊事件

  2. myChart.off('legendselectchanged')
    myChart.on('legendselectchanged', function (params) {
    myChart.setOption({
    legend:{selected:{[params.name]: true}}
    })
    console.log('點擊了', params.name);
    });
    完整代碼
    <template>
    <div id="echarts">
    <div >
    <div>
    <div id="myChart" :style="{ width: '600px', height: '300px' }"></div>
    </div>
    </div>
    </div>
    </template>
    <script>
    import * as echarts from 'echarts'
    import { getarrival } from '@/api/product' //調(diào)用后臺接口
    export default {
    name: 'Echarts',
    data() {
    return {
    newData: [],
    obj:{
    id:1
    }
    }
    },
    mounted() {
    this.drawLine()
    },
    methods: {
    drawLine() {
    getarrival(this.obj).then((res) => {
    this.newData= res.data.data.arrivel_later_result.bar //接口返回數(shù)據(jù)賦值this.newData
    // 基于準備好的dom,初始化echarts實例
    let myChart = echarts.init(document.getElementById('myChart'))
    // 繪制圖表
    myChart.setOption({
    title: {
    text: this.newData.title.text,
    subtext: this.newData.title.subtext,
    left: this.newData.title.left
    },
    tooltip: {
    trigger: 'item',
    formatter: '{a}
     : {c} (u0z1t8os%)'
    },
    legend: {
    bottom: 10,
    left: 'center',
    selectedMode: false //取消圖例上的點擊事件
    },
    series: [
    {
    name: '遲到占比',
    type: this.newData.series[0].type,
    radius: '65%',
    center: ['50%', '50%'],
    selectedMode: 'single',
    data: this.newData.series[0].data,
    emphasis: this.newData.series[0].emphasis,
    label: {
    //餅圖圖形上的文本標簽
    normal: {
    show: true,
    position: 'inner', //標簽的位置
    textStyle: {
    fontWeight: 300,
    fontSize: 16 //文字的字體大小
    },
    formatter: 'u0z1t8os%'
    }
    }
    }
    ]
    })
    // 關(guān)鍵代碼
    myChart.off('legendselectchanged')
    myChart.on('legendselectchanged', function (params) {
    myChart.setOption({
    legend:{selected:{[params.name]: true}}
    })
    console.log('點擊了', params.name);
    });
    })
    },

}
}
</script>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容