javascript - 散景如何从javascript更改图形上的image_url
问题描述
我正在使用散景来绘制我的图表。所以我需要有一个图像作为背景,我需要每隔 X 秒发出一次 http 请求,并且根据 http 请求的响应,我将更改图形图像背景。
所以这是代码:
img_yellow = "http://localhost:8000/static/images/semaforo_yellow.png"
img_green = "http://localhost:8000/static/images/semaforo_verde.png"
img_red = "http://localhost:8000/static/images/semaforo_rosso.png"
p = figure(x_range=(0, 1), y_range=(0, 1))
p.image_url(url=[img_yellow], x=0, y=1)
source = AjaxDataSource(data_url="http://localhost:8000/rt/semaforo",
polling_interval=50000)
p.circle('x', 'y', source=source)
print_button = Button(label="Print")
print_button.js_on_click(CustomJS(args=dict(source=ecg_source, plot=p), code="""
console.log("pippoprint");
plot.url = "http://localhost:8000/static/images/semaforo_rosso.png";
plot.image_url = "http://localhost:8000/static/images/semaforo_rosso.png";
console.log(plot);
plot.change.emit();
"""))
在测试应用程序的那一刻,我使用了一个按钮,如果我单击此按钮,我应该更改图像,但现在不工作。
解决方案
this is not youre looking for but with server side
img_yellow = "http://localhost:8000/static/images/semaforo_yellow.png"
img_green = "http://localhost:8000/static/images/semaforo_verde.png"
img_red = "http://localhost:8000/static/images/semaforo_rosso.png"
def change_img(attr, old, new):
p.image_url.url = img_yellow
p = figure(x_range=(0, 1), y_range=(0, 1))
p.image_url(url=[img_yellow], x=0, y=1)
source = AjaxDataSource(data_url="http://localhost:8000/rt/semaforo",
polling_interval=50000)
p.circle('x', 'y', source=source)
print_button = Button(label="Print")
print_button.on_click(change_img)
推荐阅读
- javascript - 使用 const 替换 attr 值
- excel - 比较两个工作表并将匹配项和唯一值粘贴到同一工作簿的不同工作表中
- c - 为什么 GCC -O0 转换按位与并乘以分支?
- xml - 使用 XSLT 将密钥添加到 XML 中的所有子节点到 MS Access 传输
- c++ - 网格未在 Assimp 中加载
- anylogic - Anylogic:为什么在编译过程中会出现“错误:无法解决”?
- .net - F# 相同的程序集提供不同的性能
- javascript - 为什么 TypeScript 会生成旧的 JS 文件?
- azure-devops - 开发者 ID 在审批和检查中不可见
- ruby-on-rails - 如何从给定的 acces_token 获取 user_id 到 rails API(我使用 google omniAuth)