I have the following ECharts code that can be replaced using this link:
import * as echarts from 'echarts';
type EChartsOption = echarts.EChartsOption;
var chartDom = document.getElementById('main')!;
var myChart = echarts.init(chartDom);
var option: EChartsOption;
const values = [0, 0, 0, 0, 1];
const names = ['A', 'B', 'C', 'D', 'E'];
const initialValues = values.map((v, i) => ({ name: names[i], value: v }));
option = {
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b} : {c} ({d}%)'
},
legend: {
bottom: 10,
left: 'center',
data: names
},
series: [
{
type: 'pie',
radius: '65%',
center: ['50%', '50%'],
selectedMode: 'single',
data: initialValues,
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
option && myChart.setOption(option);
An issue arises when there is only one value
.
const values = [0, 0, 0, 0, 1];
Upon selecting item E for label removal, 1/4 of all items are displayed, even though they are zero.
https://i.sstatic.net/eyIpv.png
My concern is how to prevent any of these items from being displayed and show 0% for item E.
Something along the lines of this image