I have a app that stores the value when you complete a simluation, the first question have 4 alternatives, if the user press one of theese he gets a new alternative and each alternative have different choises like:
Beginning of simulation
[one] [two] [tree] [four]
If a user press [one] he gets alternatives: [red] [green] [blue]:
If a user press [two] he gets alternatives: [apple][kiwi]:
If a user press [tree] he gets alternatives: [sky] [ocean] [dirt] [earth]:
If a user press [four] he gets alternatives: [black][red]
I have stored the value of the end results in MongoDB and i would like to use it in ChartJS to create a Pie chart so i can see what people are selecting from the start of the simulation in each [one] [two] [tree] [four].
I also need to keep the chartjs updated so when a customer do a simulation it should add another value to the chartjs
So the question is how can i make a function that adds new values from the simulation and shows it in the chartJS
here is the simulation database
const SIMULATION = [
{
id: "1",
name: "one",
applications: [
{
id: "A10",
name: "red",
},
{
id: "A20",
name: "green",
},
{
id: "A30",
name: "blue",
},
],
},
{
id: "2",
name: "two",
applications: [
{
id: "B1",
name: "apple",
},
{
id: "B2",
name: "kiwi",
},
],
},
{
id: "3",
name: "tree",
applications: [
{
id: "C1",
name: "sky",
},
{
id: "C2",
name: "ocean",
},
{
id: "C3",
name: "dirt",
},
{
id: "C4",
name: "earth",
},
],
},
{
id: "4",
name: "four",
applications: [
{
id: "D1",
name: "black",
},
{
id: "D2",
name: "red",
},
],
},
];
I need to filter the respone I get in:
{
id:"1",
name: "two",
application: "red"
}
{
id:"3",
name: "one",
application: "kiwi"
}
to add upp in the chartJs pie