nodejs utilising a route within a route to access data example

I have a route which generates 5 random numbers and forms it to an array. I want to use this array to populate a chart using chartist.

I can presently used fixed data and graph it, now I want to link up the two.

function show_graph() {             myChart.update({             labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],             series: [                 [1, 2, 5, 2, 1]             ]         });     } 

I then have this server route which generates the 5 values

router.get("/random", function(req,res) {     var arr = [];     while(arr.length < 5){         var r = Math.floor(Math.random() * 100) + 1;         if(arr.indexOf(r) === -1) arr.push(r);     }     console.log(arr);     res.status(200).send({results: arr}); }); 

My question is how do I use them together. So I can use this results variable to populate my series. Do I need to use re direct or how do I call the route as I just want the result.

Note I am using nodejs with express and my charting api is chartist.

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.