[英]Is it possible to change text in hover tool-tip for Plotlyjs bubble chart?
我的網站上有一張Plotlyjs氣泡圖。 懸停時,工具提示會顯示x,y和文本。 我想在工具提示中使用自定義文本,此功能是否可用?
示例: http : //codepen.io/sushilaitian/pen/NbGZzq
var myPlot = document.getElementById('my-graph');
Plotly.d3.csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv', function(err, rows){
var YEAR = 2007;
var continents = ['Asia', 'Europe', 'Africa', 'Oceania', 'Americas'];
var POP_TO_PX_SIZE = 2e5;
function unpack(rows, key) {
return rows.map(function(row) { return row[key]; });
}
var data = continents.map(function(continent) {
var rowsFiltered = rows.filter(function(row) {
return (row.continent === continent) && (+row.year === YEAR);
});
return {
mode: 'markers',
name: continent,
x: unpack(rowsFiltered, 'lifeExp'),
y: unpack(rowsFiltered, 'gdpPercap'),
text: unpack(rowsFiltered, 'country'),
marker: {
sizemode: 'area',
size: unpack(rowsFiltered, 'pop'),
sizeref: POP_TO_PX_SIZE
}
};
});
var layout = {
xaxis: {title: 'Life Expectancy'},
yaxis: {title: 'GDP per Capita', type: 'log'},
margin: {t: 20},
hovermode: 'closest'
};
Plotly.plot('my-graph', data, layout, {showLink: false});
});
setTimeout(function(){
myPlot.on('plotly_click', function(data){
var pts = '';
for(var i=0; i < data.points.length; i++){
pts = 'x = '+data.points[i].x +'\ny = '+
data.points[i].y.toPrecision(4) + '\n\n';
}
alert('Closest point clicked:\n\n'+pts);
});
}, 5000);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.