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

176
Visualizações
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 Respostas
Responde à pergunta

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 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