Redrawing a graph dynamically every second

283 Views Asked by At

I'm reading data from a constantly updated text file, roughly around every 0.5-1 second. Currently I have it worked out by using the refresh header in my PHP script, and I'm using jpgraph library to generate the graph. However the problem is that the graph is rather large, around 1500x900, and so the image ends up taking the entire refresh time to reload.

I was wondering if there is some other way that lets the graph be generated without having to send so much data to the client using jpgraph? I assume that I might be using the library wrong.

Or should I just use a client side graph charter and give access to the text file on the server to the client side?

2

There are 2 best solutions below

1
On

It would make more sense to use javascript to fetch the the graph data in JSON format, while using a client side chart like Google Charts - it's awesome, try it.

https://developers.google.com/chart/

1
On

I would compare the size of the raw text data(compressed with gzip of course) to the size of the generated image(most image formats are already compressed by definition). The compressed text is probably much smaller, and so would be a good choice. This assumes the client doesn't have any realistic cpu power limitations that might make graph rendering and processing too expensive.

You could also look at keeping a socket connection to the server open, and just pushing new data as it comes. That would reduce the fixed cost overhead of each http request.

I don't know your data, but maybe you could only send a delta of the data? The delta is the data points that actually changed.