Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!