Cod*_*n25 3 charts plotly angular plotly.js
如果将鼠标悬停在图例上,如何显示与图例中所述不同的跟踪名称?
目前我像这样推送我的配置:
...
const chart_entry = {
x: x,
y: y,
type: 'scatter',
name: legendName
};
this.graph.data.push(chart_entry);
...
Run Code Online (Sandbox Code Playgroud)
但是,通过这种方式,无论是在图例中还是在将鼠标悬停在一行上时,都会对图例中的相同名称进行寻址(legendName 变量)。
但我希望悬停有一个单独的名字。
那可能吗?
小智 5
使用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, {}, {});Run Code Online (Sandbox Code Playgroud)
<head>
<!-- Plotly.js -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<div id="myDiv"></div>
</body>Run Code Online (Sandbox Code Playgroud)