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);
}