plotly - Graph 的工具提示未正确显示

标签 plotly

我引用本教程创建了绘图 https://plot.ly/javascript/filled-area-plots/ .But tool tip is not coming correctly for left and right side.Some part of tooltip is hiding.不应该。

当鼠标悬停在图表的左侧时,是否有可能在右侧同时显示工具提示,反之亦然?

我也在分享截图,请指导。

enter image description here

这是我的代码:-

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>  
<div id="myDiv" style="width: 480px; height: 400px;"><!-- Plotly chart will be drawn inside this DIV --></div>
<script>
var abc = ['2013-10-04 02:23:00', '2013-10-22 12:23:00',  '2013-11-04 20:23:00', '2013-11-020 10:23:00','2013-12-04 15:10:45', '2013-12-26 06:03:00'];
abc[6]='2014-05-02 20:23:00';
var trace1 = {
x: abc,
y: [1, 3, 6,9, 4, 5,8],
  fill: 'tozeroy',
  fillcolor: 'red',
  text: server1,
  hoverinfo: "x+y+text",
  type: 'scatter',
  mode:"markers",
  marker:
  {
    size:4,
    color:"gray"
  },
  uid:"c2e171",
  dragmode:"turntable"
};
var layout = {
  margin: {
    l: 35,
    r: 40,
    b: 50,
    t: 10
  },
  legend: {
    "orientation": "h"
  },
  xaxis: {
    showgrid: false,
    showline: true,
    ticks: "outside"
  },
  yaxis : {
    fixedrange: true,
    showgrid: false,
    showline: true,
    ticks: "outside"
  },
  dragmode:false,
};
var data = [trace1];
Plotly.newPlot('myDiv', data,layout, {modeBarButtonsToRemove: ['sendDataToCloud','hoverCompareCartesian','zoom2d','pan2d','select2d','lasso2d','autoScale2d','hoverClosestCartesian','toggleSpikelines']});

var plotDiv = document.getElementById('myDiv');
plotDiv.on('plotly_relayout',
function(eventdata){  
    alert( 'ZOOM!' + '\n\n' +
        'Event data:' + '\n' + 
         JSON.stringify(eventdata) + '\n\n' +
        'x-axis start:' + new Date(eventdata['xaxis.range[0]'])+ '\n' +
        'x-axis end:' + new Date(eventdata['xaxis.range[1]']));
        var xVal = new Date(eventdata['xaxis.range[0]']);
        var yVal = new Date(eventdata['xaxis.range[1]']);
});

</script>
</body>

最佳答案

您可以尝试增加工具提示的 z-index。我使用 chrome 开发人员工具中的元素概述对其进行了调查。以下对象结构 (DOM) 在工具提示 <div id="myDiv"> 的绘图中有条不紊地构建-> <div class="plot-container plotly"> -> <div class="svg-container"> -> <svg class="main-svg"> -> <g class="hoverlayer">

所以只需在您的 html 或类似这样的东西上附加 css:

<style>
  #myDiv .hoverlayer:{
    z-index: 100
  }
</style>

请注意,在我看来这是一个肮脏的解决方案。但我不知道如何仅使用库 api 来解决它

关于plotly - Graph 的工具提示未正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43612266/

相关文章:

python - 如何绘制每个政党的时间序列图以及他们每年获得的总票数

Plotly.js:锁定 y 轴以避免负值

python - 绘图对象中的颜色离散序列

python - 如何在 Plotly 中的特定条形之间添加间隙

python - 仪表板绘图值错误: Invalid value

python - Plotly:如何使用 updatemenus 更新一个特定的跟踪?

r - 部署到 Shiny 的服务器后找不到绘图变量

python - Plotly:如何自定义图例顺序?

r - 绘图分组条形图不显示负值

r - ggplotly 结合scale_x_continuous删除轴标题