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

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

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