Skip to main content

How do I merge two items in a pie chart into one for counting?

1. Problem scenarios

Assume that you need to use pie charts to count the number of fruit types, but in the process of input, you can enter "apple" into "Little Apple 」. The following pie chart effect is obtained:


Question:How do I put little Apple and Apple in the same category for statistics?


2. Solution

View the following video for specific settings:


Code snippet:

function afterFetch(content) {
const categies = (content.series[0] || {}).data || [];
categies.forEach(item => {
if (item.name === '苹果' || item.name === '小苹果') {
item.name = '苹果';
}
});
content.series[0].data = categies;
return content;
}


From one example to another:

Suppose you not only classify "apple" and "Little Apple" as "apple", but also need to classify "pineapple" and "Pineapple" as "Pineapple". What should you do?

Then you only need to add another judgment.

function afterFetch(content) {
const categies = (content.series[0] || {}).data || [];
categies.forEach(item => {
if (item.name === '苹果' || item.name === '小苹果') {
item.name = '苹果';
}
if (item.name === '菠萝' || item.name === '凤梨') {
item.name = '菠萝';
}
});
content.series[0].data = categies;
return content;
}


YIDA in order to better optimize the content and quality of YIDA user manual, it takes you 3-5 minutes to fill in the document feedback questionnaire. The document feedback questionnaire is submitted anonymously, and the questionnaire information is only used for YIDA document experience feedback collection. Thank you for your support for YIDA!

Click here to fill in the questionnaire


-------------------- Get the latest information YIDA, welcome to follow US--------------------

This doc is generated using machine translation. Any discrepancies or differences created in the translation are not binding and have no legal effect for compliance or enforcement purposes.
Copyright © 2024钉钉(中国)信息技术有限公司和/或其关联公司浙ICP备18037475号-4