I have the following code written in ECharts and you can replace it in the link: https://echarts.apache.org/examples/en/editor.html?c=pie-rich-text&lang=ts
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);
The problem occurs when I have only one value.
const values = [0, 0, 0, 0, 1];
When selecting item E to remove the labels, 1/4 of all items appear, but they are zero.
My question is how to ensure that none of these items appear and there is 0% in item E.
Something similar to this


The values are actually ratios, as the pie chart can only represent proportions. Therefore, if all values are 0, the chart correctly draws that the values cut out the same proportion from the chart. If the value is "empty", meaning there is "none", then
nullshould be applied. If all values arenull, then it is correct not to draw a pie chart, as we have no data for it.By the way, the community has already discussed the error:
Solution
So, the answer is how we can draw a circle indicating an "empty pie chart" if all values are
null, meaning we have no values.If all values are null, a gray circle will appear; unfortunately, the R cannot contain a percentage, so the circle must have a fixed width OR you need to dynamically calculate and provide the value of r. I have now fixed it to 100, so the circle and the gray graphic element have a fixed width.
Example
Extra
I omitted the variable named
initialValuesfrom the formula, you'll find it inserted into thedataparameter. If you additionally include there that every 0 value should be converted to null, the chart will consider 0 as empty as well.