简体   繁体   English

带有选择的交互式 vega-lite / vega 图表

[英]Interactive vega-lite / vega chart with selection

I'm trying to build an interactive vega-lite dashboard where I have got this world map vega editor link我正在尝试构建一个交互式 vega-lite 仪表板,我在其中获得了这个世界地图vega 编辑器链接

Based on the selection of a country I'm trying to display another graph below(vconcat or outside)根据选择的国家/地区,我尝试在下方显示另一个图表(vconcat 或外部)

Is it possible to do it outside this chart without using vconcat or I can do it only by vconcat?是否可以在不使用 vconcat 的情况下在此图表之外执行此操作,或者我只能通过 vconcat 执行此操作?

Has anyone tried something similar?有没有人尝试过类似的东西?

The easiest would be to create with vconcat .最简单的方法是使用vconcat创建。

That said, there is a way to read the underlying Vega signal of the selection.也就是说,有一种方法可以读取选择的基础 Vega 信号。 Then you can use the Vega View API to trigger callback that shows another chart based on the selected data.然后,您可以使用 Vega View API 触发回调,根据所选数据显示另一个图表。

You can now use observable notebooks to achieve what you want.您现在可以使用可观察的笔记本来实现您想要的。

You create you first chart in a cell, link it to a second cell and then export the cells in your web site.您在一个单元格中创建第一个图表,将其链接到第二个单元格,然后将这些单元格导出到您的网站中。

Here's how to start in observable以下是如何开始观察

Here is the central part of the code这是代码的中心部分

letter_selected = Generators.observe(
  // selection_caught will (yield) a value promise with the selected letters
  function initialize_f(change_) {
    // creating an event listener (ie a function to attach to some DOM element)
    const signaled = (name, value) => change_(value);

    // attaching the event listener and naming it "test_selection"
    barChart.addSignalListener("test_selection", signaled);

    // check the doc ... https://github.com/observablehq/stdlib
    change_(barChart.signal("test_selection"));

    function dispose_f() {
      return barChart.removeSignalListener("test_selection", signaled);
    }

    return dispose_f;
  }
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM