[英]Get clicked mark data using react-vega and vega-lite
I have a vega-lite chart and would like to add an event listener to get the data in React, but can't seem to figure this out.我有一个 vega-lite 图表,想添加一个事件侦听器来获取 React 中的数据,但似乎无法弄清楚这一点。 Specifically I'm trying to display a table below the vega chart that depends on some attributes of the mark that has been clicked.具体来说,我试图在 vega 图表下方显示一个表格,该表格取决于已单击的标记的某些属性。
Here's the beginning of the spec:这是规范的开头:
const spec = {
width: 'container',
height: 500,
signals: [
{
name: 'click',
value: 0,
on: [{events: '*:mousedown', update: 'datum'}]
}
],
layer: [
{
mark: {type: 'point', filled: true, tooltip: {content: 'data'}},
....
And here is my latest attempt at getting the clicked point (based on https://github.com/vega/react-vega/tree/master/packages/react-vega#approach1-create-class-from-spec-then-get-a-react-class-to-use ):这是我获得点击点的最新尝试(基于https://github.com/vega/react-vega/tree/master/packages/react-vega#approach1-create-class-from-spec-then- get-a-react-class-to-use ):
const handleClick = (...args) => {
console.log(args);
}
const signalListeners = { click: handleClick };
const vegaChart = <VegaLite spec={spec} data={data} signalListeners={signalListeners}/>;
However I'm getting Cannot add invalid signal listener. Error: Unrecognized signal name: "click"
但是我得到了Cannot add invalid signal listener. Error: Unrecognized signal name: "click"
Cannot add invalid signal listener. Error: Unrecognized signal name: "click"
even though I have the click signal defined. Cannot add invalid signal listener. Error: Unrecognized signal name: "click"
即使我定义了点击信号。 Any help would be appreciated;任何帮助,将不胜感激; I can't seem to find anything like this online.我似乎无法在网上找到这样的东西。
通过将我的 vega-lite 规范编译为 vega 规范,然后添加有效的signals
块来切换到 vega。
Looks like vega-lite doesn't support signals, so the workaround is to add the signal to the compiled spec.看起来 vega-lite 不支持信号,因此解决方法是将信号添加到已编译的规范中。
This question provides a good example: What's the proper way to implement a custom click handler in vega-lite这个问题提供了一个很好的例子: 在 vega-lite 中实现自定义点击处理程序的正确方法是什么
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.