Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Chart.js how to make chart only show the most recent data

Using chart.js, html, php. I have a chart already set up and its displaying data from a database using mySQL.

My issue is, how do i only display the most recent data on the chart. I would like to only show 20 values. So if a new set of data is added to the database. Then the chart needs to update by removing the oldest value from display to make room for the new value.
I dont want to delete data from the database to do this.

any ideas on how to make this happen.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should get the last 10 values from the database like this

SELECT * FROM big_table ORDER BY A DESC LIMIT 10

And call update (https://www.chartjs.org/docs/latest/developers/updates.html)

SELECT * FROM big_table ORDER BY A DESC LIMIT 10
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading