Drawing RGraph from a webWorker

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 mario on 14th December 2012
hi there!

first of all i'd like to thank you for rgraph! :)
i find it very handy and useful!

currently i try to draw my two multi line charts from within a web worker [1] to avoid an inresponsive web interface due to high load of the main thread.
unfortunately the web workers have only limited scope, so they are not able to access the DOM.
every interaction with the DOM has to be made by the use of function calls to the main java script where the web worker was initialized.
unfortunately i have no concrete idea about the best way to draw the canvas element from the webworker. i also checked the forums and google, but had no luck.

has anyone of you ever drawn a jGraph from a web worker?
what is best practice to do this?

best regards, mario

[1] www.html5rocks.com/en/tutorials/workers/basics/
Posted by RGraph support on 14th December 2012

Because web worker threads cannot access the DOM you should use them to get data only - not create the whole chart. In the same way that you can use AJAX to get data but not create the chart.

So the Javascript for creating the chart should be in your page as normal and the worker should just be used to get the data.

PS. It's "RGraph" not "JGraph"!
Posted by mario on 14th December 2012
thanks for your fast reply!

As i have two canvas elements with 4-6 line charts each and i repain/progress them every 500ms with updated data from ajax, this causes quite heavy load on the main thread. thus i was thinking about web workers.
can you suggest any other solution to avoid inresponsive web interfaces?

thx, mario
Posted by RGraph support on 14th December 2012

Well an AJAX request is essentially like hitting refresh in your browser whereas Web Workers are permanently open connections. So using a Web Worker to just retrieve the data might be the way to go.

But keep in mind that the Web Worker should be used to get the data only - the chart should be created in your page and then it's data updated by the Web Worker.
Posted by RGraph support on 14th December 2012

A web worker combined with Web Sockets that is - so a new thread (the Web Worker) opens a connection to your server to retrieve the data (the Web Socket).

Add a reply

« Back to message list