我正在使用highcharts,我想从我的web-worker更新highcharts系列。我的web-worker正在通过xmlhttprequest从我的api接收数据,现在我想在不刷新网页的情况下更新我的图表,我如何将这些数据传递给highcharts系列?
发布于 2017-07-05 14:47:07
您需要使用onMessage事件,并将消息从worker发送到客户端。消息应该是字符串对象或数组。
在你的主代码中:
var worker = new Worker('w/main-worker.js');
worker.postMessage('message to worker');
worker.onmessage = function(e) {
console.log(e.data);
// do stuff with data from worker
};在您的worker中:
// do stuff
// when stuff is ready
postMessage(myStuff);
// handle messages from the main thread
onmessage = function(e) {
console.log(e.data);
// do stuff with message from main thread
};我这里有几个演示:https://github.com/mchaov/WebWorkers,这里有类似于您的用例的演示。
https://stackoverflow.com/questions/42583432
复制相似问题