Thursday, 4 May 2017

How to retrieve stats in JSON file and build a bar chart with ChartJS

I'm trying to store data (statistics) in JSON file everyday. To do that I'm using json-file in my NodeJS app.

My code work well, each day, a new field is created in stats.json. So now I have this JSON :

{
  "4/5/2017":5,
  "5/5/2017":3
  ...
}

If json-file find a date == date now in the JSON file, I add 1 to the counter. If not a new field with the new date is created.

The question is how to retrieve these values, my objective is to create a bar chart with ChartJS and take the last 20 days to build it. (Other days will be shown in a simple table). I can't imagine how to work with this type of data. On chartjs (client side) how to put in the labels array the dates, and for each labels (so data[] with chartjs) apply the number of visit this day.

I already try to play with object in my JSON. Without success. I can give you my code that generate the JSON file with json-file if you want

Thank you very much.



via Dlazzy

No comments:

Post a Comment