I have to display data from the JSON file we got.
There are a few entries that have a duplicate object. You can see it here :
2 categories called “fruit” which each have a different number. However, The way my code currently is set up doesn’t seem to add-up both numbers and showcase it as one.
It results in the following sight :
As you can see, the numbers on “Ma” and “Wo” overlap. Also, the values are set to the very first value they find. No idea what happened on the “Zo” rectangle-display, but yeah.
My code is the following :
for (i = 0; i < beterData.results.length; i++) {
var dagen = beterData.results[i];
text("Gegeten fruit", width / 3 + 50, 150);
textSize(20);
fill(0);
text(dagenAfkorting[i], 165 + i * 95, 500)
// loopen door activiteiten per individuele dag
for (j = 0; j < dagen.activity.length; j++) {
var fruit = dagen.activity[j];
//de fruit string zoeken in de categorie-sectie
if (fruit.category == "fruit") {
console.log(fruit.category);
if (fruit.quantity < dagen.goals[j].quantity) {
fill(255, 0, 0);
} else {
fill(0, 255, 0);
}
rect(165 + i * 95, 480, 30, -fruit.quantity * 25);
fill(0);
text(fruit.quantity, 100 + i * 70, 200);
}
}
How can I add-up the duplicate “fruit” strings to 1 number and showcase it on screen?
Important EDIT: I am not allowed to change anything in the JSON-file