【发布时间】:2021-04-12 11:14:41
【问题描述】:
我正在 Vue.js SPA 中使用 vega-lite 绘制条形图。主数据层的编码部分如下所示:
encoding: {
x: {field: 'word', type: 'ordinal', sort: '-count'},
y: {field: 'count', type: 'quantitative'},
tooltip: [{field: 'word'}, {field: 'count'}, {field: 'doc_count'}]
}
…在更新图表的 Vue 组件方法中,我有这个:
vegaEmbed('#vis', spec)
.then(({_spec, view}) => {
view.addEventListener('click', function (event, item) {
if (item) {
vueComponent.onWordClicked(item.datum.word);
}
})
})
……为了完成所有这些,它称之为:
onWordClicked(word) {
this.$router.push({path: 'words', params: {word: word}});
}
所有这些都按我的预期工作:将鼠标悬停在一个栏上,显示一个工具提示,单击该栏,然后导航到 SPA 中的另一条路线。
但是……工具提示会一直显示在屏幕上,除非您导航回图表页面并将鼠标悬停在条形上,在这种情况下,可以重新调用工具提示,然后在鼠标移出时将其关闭。
关于如何在 Vue 路径更改时使工具提示消失的任何想法?我尝试过使用view.tooltip(...) 方法,但怀疑这有点矫枉过正(我对默认工具提示很满意),甚至可能无法解决我的问题。
谢谢。
【问题讨论】:
标签: javascript vue.js vega-lite vega