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

65
Vistas
Data refresh issue with D3 burnup chart

I'm building a "burnup" d3 line chart attempting to forecast trends based on scope and historic data.

A dropdown box selects the data to be displayed, ideally transitioning between lines, but I'm having troubles clearing the previous data displayed, and instead the new lines are written over the existing lines.

Link to the jsfiddle: https://jsfiddle.net/dgf1vts8/

Currently doing it this way (line 329):

svg.append("path")
      .datum(selectedData)
      .attr("class", "line")
      .attr("d", line);

other approach I've tried and did not work (line 318)

var lines = svg.selectAll(".line").data(selectedData).attr("class","line");
    lines.transition().duration(500).attr("d",line);
    lines.enter()
      .append("path")
      .attr("class","line")
      .attr("d",line);
    lines.exit()
      .remove();

Any guidance with this would be much appreciated

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Since you only append new object in your update function, every time that function is invoked a new line is added to the chart.

The easiest workaround would be to just remove all path objects before you add the new ones.

svg.selectAll("path").remove();

However, the enter-update-exit logic for this would be

  var lines = svg.selectAll(".line").data(selectedGroup);
  lines.enter() // enter any new data
    .append("path")
    .attr("class", "line")
    .merge(lines)
    .datum(selectedData)
    .attr("d", line);
  lines.exit() // exit
    .remove();

The logic for lines is different as for e. g. points or bars, where you need to create an object for every data point of the time series. For lines you only have to create one path object. This is why the data binding to the selection

svg.selectAll(".line")

should be the label of the line. If you work with multiple lines, it is often best to nest the array.

If you start a new project you should probably use the current version d3v7 and not d3v3, since there have been major changes which break compatibility. I reduced your fiddle and changed all the parts to make it work with d3v7: https://jsfiddle.net/esd4kofr/1/

about 4 years ago · Juan Pablo Isaza Denunciar
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