简体   繁体   English

Plotly.js 轴单击/拖动事件

[英]Plotly.js Axis Click/Drag Event

I have multiple y-axis in a line chart.我在折线图中有多个 y 轴。 Only the last y-axis related grid lines are shown by default.默认情况下,仅显示最后一个与 y 轴相关的网格线。 If the user clicks on any other y-axis, grid lines for that y-axis should be shown.如果用户单击任何其他 y 轴,则应显示该 y 轴的网格线。 But I am unable to find any event in plotly.js which triggers when the axis is clicked or dragged.但是我在 plotly.js 中找不到任何事件,该事件在单击或拖动轴时触发。

Sorry, I can't comment yet.抱歉,我还不能发表评论。 Here's a rather hacky way of registering clicks on yaxis labels.这是在 yaxis 标签上注册点击的一种相当老套的方法。 Not sure if that's helpful.不确定这是否有帮助。

 var trace1 = { x: [1, 2, 3], y: [40, 50, 60], name: 'yaxis data', type: 'scatter' }; var trace2 = { x: [2, 3, 4], y: [4, 5, 6], name: 'yaxis2 data', yaxis: 'y2', type: 'scatter' }; var data = [trace1, trace2]; var layout = { title: 'Double Y Axis Example', yaxis: {title: 'yaxis title'}, yaxis2: { title: 'yaxis2 title', titlefont: {color: 'rgb(148, 103, 189)'}, tickfont: {color: 'rgb(148, 103, 189)'}, overlaying: 'y', side: 'right' } }; Plotly.newPlot('chart', data, layout); var myPlot = document.getElementById('chart'); myPlot.on('plotly_afterplot', function(){ Plotly.d3.selectAll(".nsdrag.drag.cursor-ns-resize").on("click", function() { var target = Plotly.d3.event.target; console.log('clicked on', target.dataset.subplot); }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/1.49.5/plotly.min.js"></script> <div id="chart"> </div>

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

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