How to make Plotly.js listen the click events of the tick labels?(如何让 Plotly.js 监听刻度标签的点击事件?)
问题描述
因此,在此动态图表中,我想在单击任何 Y 轴的刻度标签时更改 Y 轴的最小值和最大值.
So, in this dynamic chart, I want to change the Y-axis' min and max values when any of the Y-axis' Tick Label is clicked.
推荐答案
您可以为所有 y-ticks 添加一个 d3 事件侦听器,并确保 SVG 组获取所有 活动.将整个片段包装在 Plotly 的 afterplot
事件中可确保事件侦听器在更新图形后不会丢失.
You could add a d3 event listener to all y-ticks and make sure that the SVG group gets all the events.
Wrapping the whole snippet in Plotly's afterplot
event makes sure that the event listener does not get lost after updating the graph.
var trace1 = {
x: [1, 2, 3, 4],
y: [10, 15, 13, 17],
type: 'scatter'
};
var trace2 = {
x: [1, 2, 3, 4],
y: [16, 5, 11, 9],
type: 'scatter'
};
var data = [trace1, trace2];
var myPlot = document.getElementById('myDiv');
Plotly.newPlot(myPlot, data);
myPlot.on('plotly_afterplot', function(){
Plotly.d3.selectAll(".yaxislayer-above").selectAll('text')
.on("click", function(d) {
alert("Hello, I am " + d.x);
});
});
.yaxislayer-above {
cursor: pointer;
pointer-events: all;
}
<script src="aHR0cHM6Ly9jZG4ucGxvdC5seS9wbG90bHktbGF0ZXN0Lm1pbi5qcw=="></script>
<div id="myDiv"></div>
这篇关于如何让 Plotly.js 监听刻度标签的点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何让 Plotly.js 监听刻度标签的点击事件?


- Flexslider 箭头未正确显示 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Fetch API 如何获取响应体? 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01