As shown in the figure, I want to directly obtain the name of each segment of the pie chart in the background and use it as the legend directly, replacing the red "test" at the top. How to get the name of each segment? Thanks!
var myChart = echarts.init(document.getElementById('main')),
option = {
tooltip: {},
legend: {},
series: [{
name: '訪問來源',
type: 'pie',
radius: '55%',
center: ['50%', '60%'],
data: [],
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}]
};
myChart.setOption(option);
//以下為ajax獲取到的數(shù)據(jù)
var data = [{
value: 335,
name: '直接訪問'
}, {
value: 310,
name: '郵件營銷'
}, {
value: 234,
name: '聯(lián)盟廣告'
}, {
value: 135,
name: '視頻廣告'
}, {
value: 1548,
name: '搜索引擎'
}],
legends = []
data.forEach(function(e, i) {
legends.push(e.name)
})
myChart.setOption({
legend: {
data: legends
},
series: [{
data: data
}]
});