SOURCE

console 命令行工具 X clear

                    
>
console
const myChart = echarts.init(document.getElementById('container'))

const data = [
    {
        name: '淘宝',
        value: 12345
    },
    {
        name: '京东',
        value: 23456
    },
    {
        name: '拼多多',
        value: 5634
    },
    {
        name: '闲鱼',
        value: 2347
    },
    {
        name: '得物',
        value: 444
    }
]

const option = {
    series: [{
        type: 'pie',
        data,
        label: {
            formatter: (args) => {
                return args.name + '\n' + args.percent + '%'
            }
        },
        selectedMode: 'single', // 选中后偏离圆点
    }]
}

myChart.setOption(option)

const btn = document.getElementById('btn')
const btn2 = document.getElementById('btn2')
const btn3 = document.getElementById('btn3')
const btn4 = document.getElementById('btn4')

btn.onclick = () => {
    myChart.dispatchAction({
        type: 'highlight', // 触发高亮事件
        seriesIndex: 0, // 系列的索引
        dataIndex: 1, // 数据的索引
    })
}

btn2.onclick = () => {
    myChart.clear() // 清除数据
}

btn3.onclick = () => {
    myChart.setOption(option)
}

btn4.onclick = () => {
    myChart.dispose() // 销毁实例
}
<button id="btn">模拟</button>
<button id="btn2">清除</button>
<button id="btn3">重置</button>
<button id="btn4">销毁</button>
<div id="container"></div>
#container {
    width: 600px;
    height: 400px;
    background: linear-gradient(135deg,#fce38a,#f38181);
}

本项目引用的自定义外部资源