07-24-2023, 09:42 AM
My code gathers all categories from a CSV file, sorts and grabs top 10 categories and the top 10 result are displayed on a chart. The code works fine if the gategory found is 10, but if it is less than 10 no chart is displayed..basically code dies.
I am a newbie when it comes to coding and the code was passed on to me by someone else who is not available. What I would like to add is an if cases that checks:
- Gather all category, sort
Set category to 1 to 10
- if category is null, stop. Chart has no value
- if category=1 ===> Display found value
- if category=2 ===> Display found value
- if category=3 ===> Display found value
- if category=3 ===> Display found value
- So on, so on..untill it reaches to 10
<br/>
//collect top 10 cat from array
catArray.sort(sort_by("count", false, function (a) {
return parseInt(a)
}));
var categorytop10 = new Array(catArray[0]["tier3"], catArray[1]["tier3"], catArray[2]["tier3"], catArray[3]["tier3"], catArray[4]["tier3"], catArray[5]["tier3"], catArray[6]["tier3"], catArray[7]["tier3"], catArray[8]["tier3"], catArray[9]["tier3"]);
var categorytop10Count = new Array(catArray[0]["count"], catArray[1]["count"], catArray[2]["count"], catArray[3]["count"], catArray[4]["count"], catArray[5]["count"], catArray[6]["count"], catArray[7]["count"], catArray[8]["count"], catArray[9]["count"]);
Any help is appreciated. Thanks
I am a newbie when it comes to coding and the code was passed on to me by someone else who is not available. What I would like to add is an if cases that checks:
- Gather all category, sort
Set category to 1 to 10
- if category is null, stop. Chart has no value
- if category=1 ===> Display found value
- if category=2 ===> Display found value
- if category=3 ===> Display found value
- if category=3 ===> Display found value
- So on, so on..untill it reaches to 10
<br/>
//collect top 10 cat from array
catArray.sort(sort_by("count", false, function (a) {
return parseInt(a)
}));
var categorytop10 = new Array(catArray[0]["tier3"], catArray[1]["tier3"], catArray[2]["tier3"], catArray[3]["tier3"], catArray[4]["tier3"], catArray[5]["tier3"], catArray[6]["tier3"], catArray[7]["tier3"], catArray[8]["tier3"], catArray[9]["tier3"]);
var categorytop10Count = new Array(catArray[0]["count"], catArray[1]["count"], catArray[2]["count"], catArray[3]["count"], catArray[4]["count"], catArray[5]["count"], catArray[6]["count"], catArray[7]["count"], catArray[8]["count"], catArray[9]["count"]);
Any help is appreciated. Thanks