提问人:mHelpMe 提问时间:10/27/2023 更新时间:10/27/2023 访问量:35
动态嵌入散景图
embed bokeh chart dynamically
问:
我正在尝试在我的网页上动态嵌入散景图。我正在使用from bokeh.embed导入组件来为我提供脚本和div组件以嵌入到我的页面中。但是,我无法弄清楚如何将脚本添加到我的页面。下面是我正在使用的javascript,我可以看到它被添加到页面上,但作为一个字符串,它没有做任何事情。
JavaScript的
add_chart(div, script) {
let ele = document.createElement('div');
ele.innerHTML = div;
document.getElementById('my_ele').appendChild(ele);
let scp = document.createElement('script');
scp.type = script;
//scp.setAttribute('type', script);
document.body.appendChild(scp);
}
脚本组件
<script type="text/javascript">
(function() {
const fn = function() {
Bokeh.safely(function() {
(function(root) {
function embed_document(root) {
const docs_json = '{"28b69ac1-333a-4628-a3f8-8b816b38d636":{"version":"3.2.0","title":"Bokeh Application","roots":{"p1131":"df455907-9e51-4ef2-9f1a-696441204478"},"root_ids":["p1131"]}];
... lots of lines...
root.Bokeh.embed.embed_items(docs_json, render_items);
}
if (root.Bokeh !== undefined) {
embed_document(root);
} else {
let attempts = 0;
const timer = setInterval(function(root) {
if (root.Bokeh !== undefined) {
clearInterval(timer);
embed_document(root);
} else {
attempts++;
if (attempts > 100) {
clearInterval(timer);
console.log("Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing");
}
}
}, 10, root)
}
})(window);
});
};
if (document.readyState != "loading") fn();
else document.addEventListener("DOMContentLoaded", fn);
})();
</script>
答: 暂无答案
评论