Skip to main content

How do I count two items in a pie chart?

1. Problem scenarios

Form entry data

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:

Effect picture

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

2. Solution

View the following steps to learn about the specific settings:

Solution

Code snippet:

function afterFetch(data, extraInfo) {
let num = 0;
for(let i = 0;i<data.length;i++){
if (data[i].field_ktwly8no === '苹果' || data[i].field_ktwly8no === '小苹果') {
num = num + data[i].field_ktwly8nq;
data.splice(i--,1)
}
console.log(data)
}
data.push({ field_ktwly8no: '苹果', field_ktwly8nq:num})

return data;
}

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.

3. Effect display

Effect display

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