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

163
Visualizações
Creating a simple bar chart in D3

I am really new to D3 and wanting to create a simple bar chart to get the gist of how D3 functions. I am using this website:

https://observablehq.com/@uwdata/introduction-to-d3-part-1

It has an online built-in repl which is how I have access to the data that is being used.

I am stuck on the second exercise where it wants use to recreate this bar chart enter image description here

Currently, this is the code I have

{
  const container = d3.create('div');
  
  const data = barData;
  
  const barChart = container.selectAll('div')
  /* TODO: Add code here to generate the bar chart within the container. */
  data.forEach(function(d) {
    var dataValue = 0 
    dataValue = d.value
  
  })
  barChart
      .data(data)
      .style('background', 'steelblue')   // Set the background color of the div to 'steelblue'
      .style('border', '1px solid white') // Set the border of the div as 'white'
      .style('font-size', 'small')        // Set the text font size in the div to 'small'
      .style('color', 'white')            // Set the text font color to 'white'
      .style('text-align', 'right')       // Set the text alignment in the div to 'right'
      .style('padding', '3px')            // HINT: CSS styles require units, not just numbers
      .style('height', '500px')
      .style('width', '960px')
  /* TODO: Add code here to finish updating the visual properties of the bars */
  
  return container.node();
}

What I assume that has to be done is looping through the dataset provided and then grabbing the values which are what I am doing but after the chart should show up with the styling that is provided. I am confused as to why nothing is displaying at all. Any help would be greatly appricated.

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

0

Use the methods:

  • merge
  • enter
  • update
  • exit to map your data 1-to-1 to a DOM element.

This article is rather old, but has very good animations how enter, update and exit work. merge is a new addition to combine enter and update. https://bost.ocks.org/mike/selection/

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