I am trying to build a pie chart and a timeline chart using echarts.js. My goal is to hide the data points that have zero values from my pie chart.
For instance, I do not want these 0's to appear:
I just want to show the data points that have non-zero values, in this case, only the joy sentiment with number of tweets 3 and its percentage (100%).
This problem is two-fold:
I want to hide the data points with non-zero values when the chart load (the first time).
I want to hide the data points with non-zero values when I move the axisPointer.
I solved the 2).
myChart.on('updateAxisPointer', function (event) {
const xAxisInfo = event.axesInfo[0];
if (xAxisInfo) {
const dimension = xAxisInfo.value + 1;
myChart.setOption({
series: {
id: 'pie',
label: {
formatter: function(params) {
if (params.data[dimension] === 0) {
return '';
} else {
return params.name + ': ' + params.value[dimension] + ' (' + params.percent + '%)';
}
}
},
encode: {
value: dimension,
tooltip: dimension
}
}
});
}
});
The logic of this code block is from the official documentation of the library, found in this example, here. The difference is that I thought the solution of hiding the data points of non zero values with the if block. And it works. When I move my mouse, and the axisPointer updates, I only see data points with non-zero values, with the pie chart correctly displaying them, like so:
However, when my chart loads the first time, I see everything, because I have the label formatter in this form in my option object:
label: {formatter: '{b}: {@Tue Jan 26, 10:00} ({d}%)'}
How can I solve this?
I should add that I am new in learning the echarts.js library, and I have not yet fully understood the above code block found in the given example. The library does not provide a complete documentation, nor it explains the given example. I am blind, searching in the dark here.
Any help would be appreciated. Thank you.
I couldn't find the complete solution you were seeking, but I did experiment with the example you provided in your question. You can visit the link I've shared below to get a better idea of what you're trying to achieve. Here's the code for your reference:
Here
Thank you.