Praveen
Praveen

Reputation: 347

D3-Updating line chart dynamically

I am new to d3, working on updating the line chart dynamically based on interval, i want the old data to be moveout/exit and update with new data, i am stuck at a position where i can see new data joins the chart but old data is not moving out/exiting. Can someone please help me out on this issue, any help is much appreciated.

Copied from d3noob'slink with little variation of injecting data to chart

Plunker link

Also i am trying to add the circles for each point, currently the single circle is added on top of Y-axis for some reason.

Upvotes: 1

Views: 611

Answers (1)

Sahan Serasinghe
Sahan Serasinghe

Reputation: 1651

While checking d3noob's link I realized that he's using 2 datasets as data.csv and data-alt.csv. During the second run of updateData function it always gets data-alt.csv

So, in order to answer your question,

  1. First, you need to get your data generation logic correct. Since you are generating random numbers you need to make sure your randomPoints() function generates proper dates that are understandable to D3

  2. Then bind the randomly generated dataset to your data variable.

  3. Finally, clear your data variable in every run of updateData function.

I have made a Plunker for you. Let me know if you need more explanation on this.

Hope this helps :)

Upvotes: 1

Related Questions