angular - 如果我将鼠标悬停在 Plotly 中,如何显示与图例中所述不同的跟踪名称?

标签 angular charts plotly plotly.js

如果将鼠标悬停在轨迹名称上,我如何显示与图例中所述不同的轨迹名称?

目前我推送我的配置是这样的:

  ...
  const chart_entry = {
    x: x,
    y: y,
    type: 'scatter',
    name: legendName
  };
  this.graph.data.push(chart_entry);
  ...

但是,通过这种方式,无论是在图例中还是在将鼠标悬停在一条线上时,都可以找到来自图例的相同名称(legendName 变量)。

但我希望悬停有一个单独的名称。

这可能吗?

最佳答案

使用 hovertemplate 选项:https://plot.ly/javascript/reference/#scatter-hovertemplate

var trace1 = {
  x: [1, 2, 3, 4],
  y: [10, 15, 13, 17],
  type: 'scatter',
  name: 'legend name 1',
  hovertemplate: '%{y}<extra>hover name 1</extra>'
};

var trace2 = {
  x: [1, 2, 3, 4],
  y: [16, 5, 11, 9],
  type: 'scatter',
  name: 'legend name 2',
  hovertemplate: '%{y}<extra>hover name 2</extra>'
};

var data = [trace1, trace2];

Plotly.newPlot('myDiv', data, {}, {});
<head>
  <!-- Plotly.js -->
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>

<body>
  
  <div id="myDiv"></div>

</body>

关于angular - 如果我将鼠标悬停在 Plotly 中,如何显示与图例中所述不同的跟踪名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59287626/

相关文章:

flash - 将任意绘图转换为交互式 map ?

angular - Cypress - 拖放 - Angular CDK

html - CSS 定位问题 [img|span]

javascript - 将 Chart.js 水平条形图标签移至右侧

python - Plotly:如何在带有刻面的图形表达图形中隐藏轴标题?

javascript - Plotly 禁用 "band behavior"缩放选择

r - 使用 R 中的 2 个以上图例到plotly/plot.ly

javascript - 订阅放置在 Promise Angular 6 中的 http.post

javascript - 如何使用 Service Worker Angular 6 在后台运行 watchposition

python - 改进子图中饼图的标签