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

173
Views
How to set up the scale with d3js?

I'm trying to build a bar chart but keep getting this error:

SyntaxError: missing ) after argument list

It says the problem is in the line of the .range() method but I don't see it. Everything looks fine to me.

I downloaded the dataset from here: https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json

let url = "data.json";

var svg = d3.select('body')
    .append('svg')
    .attr('width', 900)
    .attr('height', 460);

var yScale;

var arr = [];
    d3.json(url).then(function(data) {
        for (let i = 0; i < data.data.length; i++) arr[i] = data.data[i];
        }).then(() => 

          yScale = d3.scaleLinear()
                     .domain([0, d3.max(arr, (d) => d[1])])
                     .range([460, 0]);

    svg.selectAll('rect')
        .data(arr)
        .enter()
        .append('rect')
        .attr('fill', 'blue')
        .attr('height', d => d[1])
        .attr('width', 3)
        .attr('x', (d, i) => 4 * i)
        .attr('y', (d, i) => yScale(d[1]))

        );
        <script src="https://d3js.org/d3.v6.min.js"></script>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

With multiple lines of code, your arrow function needs curly braces

d3.json(url).then(function(data) {
    for (let i = 0; i < data.data.length; i++) arr[i] = data.data[i];
    }).then(() => {

      yScale = d3.scaleLinear()
                 .domain([0, d3.max(arr, (d) => d[1])])
                 .range([460, 0]);

    svg.selectAll('rect')
    .data(arr)
    .enter()
    .append('rect')
    .attr('fill', 'blue')
    .attr('height', d => d[1])
    .attr('width', 3)
    .attr('x', (d, i) => 4 * i)
    .attr('y', (d, i) => yScale(d[1]))

   });
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!