Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

190
Vistas
how to position custom tooltip on top of bars in plotly bar chart?

hope you are all doing good.

I stuck in an issue. I am using plotlyjs for bar charts in which I am using custom tooltip(using hover event to create custom html content). Below you can see:

<div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>
<div id="custom-tooltip">Custom tooltip</div>

var trace1 = {
  x: ['giraffes', 'orangutans', 'monkeys'],
  y: [20, 14, 23],
  name: 'SF Zoo',
  type: 'bar',
  hoverinfo: 'none'
};

var trace2 = {
  x: ['giraffes', 'orangutans', 'monkeys'],
  y: [12, 18, 29],
  name: 'LA Zoo',
  type: 'bar',
  hoverinfo: 'none'
};

var data = [trace1, trace2];

var layout = {barmode: 'stack', showlegend: false};

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

var graphElem = document.getElementById('myDiv');
const tooltipElem = document.getElementById('custom-tooltip');

graphElem.on('plotly_hover', function(data){
  const yaxis = data.points[0].yaxis;
    const xaxis = data.points[0].xaxis;
  console.log(data)
    const distY = yaxis.d2p(data.points[0].y) + yaxis._offset + 20; //
    const distX = xaxis.d2p(data.points[0].x) + xaxis._offset - 110;
 
  tooltipElem.innerHtml = '<h3>Custom tooltip</h3>';
  console.log(distX, distY)
  tooltipElem.style.left = distX + "px";
    tooltipElem.style.top = distY + "px";
    tooltipElem.style.display = "block";
  
})
 .on('plotly_unhover', function(data){

});

But I can't find a way to position the custom div at the top of bar whenever hover on any bar.

Codepen

How can i do this?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda