0

So I have a relatively big amount of data that I want to display on the line chart by using chart.js.

The problem

My dataset looks like so:

 [{label: 'Mon Feb 19 2018 21:02:38 GMT+0000 (GMT)', value: 0.2 },
  {label: 'Mon Feb 19 2018 21:02:39 GMT+0000 (GMT)', value: 0.1 },
  {label: 'Mon Feb 19 2018 21:02:40 GMT+0000 (GMT)', value: 0.5 },
  {label: 'Mon Feb 19 2018 21:02:41 GMT+0000 (GMT)', value: -0.3 },
  {label: 'Mon Feb 19 2018 21:02:52 GMT+0000 (GMT)', value: -0.3 }]

I am able to create a chart from this data that contains 5 labels on XAxis and 5 records on YAxis. Easy peasy.

So my records happen in a few seconds one after another and this is very easy to put on the chart. However, I cumulate the data over time so my first time can be:

{label: 'Mon Feb 19 2018 21:02:38 GMT+0000 (GMT)', value: 0.2 }, ...
{label: 'Mon Feb 26 2018 11:02:38 GMT+0000 (GMT)', value: 0.2 }]

Therefore, the data now on the graph should be auto-scaled showing properly the line over that from the first date to the last date from the period with some labels in between.

The only ways that I came up with were focusing on serialising my data, but this is a very hard and tedious way. I do not want to be re-inventing the wheel if that could be handled within the library. From what I have seen so far this is a very powerful library and I think that such thing can be handled if the library is used properly.

I would really appreciate if anyone who has the experience with this library could help me out with writing a code for this task, or point me in the right direction.

Adrian Grzywaczewski
  • 868
  • 1
  • 12
  • 25

1 Answers1

0

This may be what you need. You basically just need to push the new points onto the existing label and value arrays and call the chart's update method.

Nick Swope
  • 331
  • 2
  • 7