Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
Add a subclass in d3 chart hierarchy

I was trying to add small triangle below tooltip and above bar.

For that I was following this document - http://bl.ocks.org/caged/6476579

For tooltip , I have written below code -

var tip = d3Tip()
  .attr("class", "d3-tip")
  .style("line-height", 1)
  .style("font-weight", "bold")
  .style("padding", "12px")
  .style("background", "rgba(0, 0, 0, 0.8)")
  .style("color", "#fff")
  .style("border-radius", "2px")
  .attr("class", ":after")
  .style("box-sizing", "border-box")
  .style("display", "inline")
  .style("font-size", "10px")
  .style("width", "100%")
  .style("color", "rgba(0, 0, 0, 0.8)")
  .style("content", "\\25BC")
  .style("position", "absolute")
  .style("text-align", "center")
  .offset([-10, 0])
  .html(function (_data, indexedData) {
    var htmlToolTip = "";
    keys.map((key, index) => {
      htmlToolTip +=
        "<strong>" +
        key +
        " : </strong> <span style='color:red'>" +
        indexedData.data[key + "Value"] +
        "</span> <br>";
    });
    return htmlToolTip;
  });

Here , I am trying to add below class properties-

/* Creates a small triangle extender for the tooltip */

.d3-tip:after {
  box-sizing: border-box;
  display: inline;
  font-size: 10px;
  width: 100%;
  line-height: 1;
  color: rgba(0, 0, 0, 0.8);
  content: "\25BC";
  position: absolute;
  text-align: center;
}

But triangle not getting added below tooltip.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You first need to know what is ':after'
In CSS, ::after or (:after) creates a pseudo-element that is the last child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.

What you are doing in your code is that you are styling only d3-tip and :after is nowhere inserted in that tip.You are assuming d3-tip and :after are same elements but they are seperate. To insert that you will have to do remove css of :after element(you are adding that css to your tip parent element) and insert it later on the actual :after pseudoelement. In d3, you can use d3.insert to add a child element to the class.

Your code should look like below

var tip = d3Tip()
  .attr("class", "d3-tip")
  .style("line-height", 1)
  .style("font-weight", "bold")
  .style("padding", "12px")
  .style("background", "rgba(0, 0, 0, 0.8)")
  .style("color", "#fff")
  .style("border-radius", "2px")
  .offset([-10, 0])
  .html(function (_data, indexedData) {
    var htmlToolTip = "";
    keys.map((key, index) => {
      htmlToolTip +=
        "<strong>" +
        key +
        " : </strong> <span style='color:red'>" +
        indexedData.data[key + "Value"] +
        "</span> <br>";
    });
    return htmlToolTip;
  });

 d3.select('.d3-tip').insert(":after")
  .style("box-sizing", "border-box")
  .style("display", "inline")
  .style("font-size", "10px")
  .style("width", "100%")
  .style("color", "rgba(0, 0, 0, 0.8)")
  .style("content", "\\25BC")
  .style("position", "absolute")
  .style("text-align", "center");

d3.select('.d3-tip').insert(":after") This statement will make it child of the d3-tip and you can style it. I am sure this will fix your issue.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda