How to update a thermometer chart with data via websockets

Share RGraph:   Share or Like RGraph on Facebook!

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Gareth on 7th November 2012
Hi,

Can anyone give me some help as to how to update a thermometer chart using data received via websockets ? The idea would be that I'd like to change the color and value of the thermometer based on data received in the "onMessage" method of a websocket connection.

Thanks in advance !
Posted by RGraph support on 8th November 2012
Hi,

I don't have any experience with WebSockets, though presumably you would use the onmessage event (which I'm assuming is fired when you get new data) much like the callback for AJAX - so in this event you would create or update the thermometer. You can update it by doing this:

thermometer.value = newvalue;

And then clear the canvas and redraw it (optionally changing/setting the color too):

thermometer.Set('chart.colors', ['red']);

RGraph.Clear(thermometer.canvas);
thermometer.Draw();
Posted by RGraph support on 8th November 2012
Hi,

And you might be interested in this new basic example that retrieves a CSV file via AJAX:

www.rgraph.net/demos/index.html#basic

Add a reply




« Back to message list