Bokeh CustomJS传递Glyphs数组。

问题描述 投票:0回答:1

我正试图创建多个数字,以播撒有关国家的各种信息。除此之外,我还想设置一组按钮来隐藏所有数字中的国家图。当使用CustomJS回调时,我试图传递ColumnDataSource,将各个国家作为列,并在列中加入各自的字形。ColumnDataSource看起来像下面。

{'index': array([0, 1], dtype=int64), 'US': array([GlyphRenderer(id='1038', ...), GlyphRenderer(id='1157', ... )], dtype=object), '阿拉伯联合酋长国': array([nan, nan]), '英国': array([GlyphRenderer(id='1079', ...), GlyphRenderer(id='1198', ...)]}。

然后,我试图通过到CustomJS像下面。

callback = CustomJS(args={'source':source}, code="""..."""

然而,控制台在google chrome中显示以下错误。我很难理解,如果它不是可迭代的,是因为我在每一列中都有对象,还是因为列是字符串?

未捕获(在承诺中)TypeError。(中间值)(中间值)(中间值)(中间值)是不可迭代的。

当我直接传递一列时,它的工作原理与我所期望的一样。然而,我试图把许多国家。

callback = CustomJS(args={'source':source.data['US']}, code="""..."""

非常感谢你,托马斯

javascript python bokeh bokehjs
1个回答
0
投票

正如评论中指出的,我可以通过字典。显然是真的,我是想多了,通过传递ColumnDataSource来解决问题。

通过循环thru所有的字形来解决这个问题,就像下面的一个例子一样,让所有的字形都不可见。

callback = CustomJS(args={'source':one_line, 'countries': all_countries}, code="""
var arr_glyphs = source;
var arr_countries = countries;
var index;
var index_country;                     

for (index = 0; index < arr_countries.length; ++index) {
    for (index_country = 0; index_country < arr_countries[index].length; ++index_country) {
        arr_glyphs[arr_countries[index]][index_country].visible = false;
    };
};""")

谢谢您的帮助!

© www.soinside.com 2019 - 2024. All rights reserved.