Plotly x 轴悬停文本问题

Plotly x-axis hover text issue

在 Plotly 中使用散点图时,当我有超过 1 个具有相同 x 轴值的标记时,我无法获得悬停文本。

谁能帮我解决这个问题?

或者这是 plotly 的错误?

检查离线最近的标记。

代码在这里https://jsfiddle.net/qjdt92h2/

var trace1 = {
  x: [13.5, 12, 13, 14,13],
  y: [15, 17, 13.6, 17,18],
  text: ['4.17 below the mean', '4.17 below the mean', '0.17 below the mean', '0.17 below the mean', '0.83 above the mean', '7.83 above the mean'],
  mode: 'markers',
  name: 'Grade / Mean grade',
  marker:{
  color: 'rgb(255, 99, 132)'
  }


};

var trace2 = {
  x: [0, 20],
  y: [0, 20],
  mode: 'lines',
  name: 'Guide line',
   marker:{
  color: '#023587'
  }
};


var data = [ trace1, trace2];

var layout = {
  title:'Line and Scatter Plot'
};

Plotly.newPlot('myDiv', data, layout);

您可能正在寻找 hovermode,在您的情况下应将其设置为 closest

var trace1 = {
  x: [13.5, 12, 13, 14, 13],
  y: [15, 17, 13.6, 17, 18],
  text: ['4.17 below the mean', '4.17 below the mean', '0.17 below the mean', '0.17 below the mean', '0.83 above the mean', '7.83 above the mean'],
  mode: 'markers',
  name: 'Grade / Mean grade',
  marker: {color: 'rgb(255, 99, 132)'}
 };

var trace2 = {
  x: [0, 20],
  y: [0, 20],
  mode: 'lines',
  name: 'Guide line',
  marker:{color: '#023587'}
};


var data = [trace1, trace2];
var layout = {
  title:'Line and Scatter Plot',
  hovermode: 'closest'
};

Plotly.newPlot('myDiv', data, layout);
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<div id="myDiv"></div>