Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

244
Vistas
In D3.js, what is the difference the graphing function required to make a line graph and one required to make an area graph?

I have an application which renders a line graph from programmatically created datasets. I would like to allow users to swap between different visualization modes, but am struggling to turn my existing graph into a different variety of graph.

I wrote this code to render a line graph:

 let graph = d3.select(graphingArea).append('svg');

 ...

  if(type == "line"){
    console.log("Graph type: Line");
    for(let i = 0; i < frequencyResponseObjects.length; i++){
      graph.selectAll(".line")
      .data(sessionGraphData)
      .enter()
      .append("path")
      .attr("fill", "none")
      .attr("stroke", function(d){return color(d[0])})
      .attr("stroke-width", 1.5)
      .attr("d", function(d){
        return d3.line()
        .x(function(d){return x(+d.frequency)})
        .y(function(d){return y(+d.magnitude)})
          (d[i+1])
      })
    }
  }

That works perfectly, but I want to change it to an area graph by doing something like this:

  if(type == "area"){
    console.log("Graph type: Area");
    for(let i = 0; i < frequencyResponseObjects.length; i++){
      graph.selectAll(".line")
      .data(sessionGraphData)
      .enter()
      .append("path")
      .style("fill", "#377eb8")
      .attr("stroke", function(d){return color(d[0])})
      .attr("stroke-width", 3)
      .attr("class", "area")
      .attr("d", function(d){
        return d3.area()
        .x(function(d){return x(+d.frequency)})
        .y0(y(graphMin))
        .y(function(d){return y(+d.magnitude)})
          (d[i+1])
      })
    }
  }

That function still outputs a line graph, and I don't understand why - or how to create an equivalent function that draws an area graph.

There are D3 area graphs online, but they're different from how I constructed my line graph in ways that I don't understand. Could I get an example of how a similarly constructed area graph should look?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda