score:1
You should make use of D3's data binding approach. Mike Bostock has great docs explaining how it works. First one is somewhat outdated but still explain things clearly.
Bind the basin array to the "map.legendBasin" selection and then when you update the basin array, you can just use the enter() selection to append the new elements.
You would do something like the following:
map.legendBasin
.data(basin, function(d){return d;})//join using key
.enter()
.append("text")
.attr("x", 15)....//etc whatever stuff you want
Notice that this code is reusable for both the first time and when new elements come in. When the new array comes you can simply call this function again and only the new elements will get created as the key will match for the existing elements while it would not for the new elements hence the enter() selection will contain only the data not already appended as an element in the DOM. You may use the exit() selection in case you have to remove elements.
Source: stackoverflow.com
Related Query
- How to get d3 map to refresh with new saved data with javascript
- D3: How to refresh a chart with new data?
- How to update d3.js bar chart with new data
- NVD3 - How to refresh the data function to product new data on click
- Initiate D3.js data map with new data
- Draw a map with D3.js: How to get the right scale() and translate()?
- how to get data with tsv or csv to array in d3.js from a txt file?
- D3 How to update the chart after selection from drop down menu with new data
- How to change JSON data to Javascript array of objects with D3
- Reconstructing D3 Animated Choropleth with a new Map and Data
- How to smoothly update a D3 v4 force diagram with new data
- How to get map to show longitude and latitude accurately with d3
- How can I scale my map to fit my svg size with d3 and geojson path data
- How do you get JSON data and create a line chart with d3.js?
- Cannot get treemap to render with new JSON data
- How can I get reliable data updates with objects in D3?
- How to update a d3 grouped barchart with new data by using join in v6
- Angular - how do I get data to load with ngOnChanges
- How to update (but not redraw) a d3-geomap with new data
- How to render multi line chart with DC.js with the following type of data - JAVASCRIPT (DC.js)
- How do I create and write to a new file (csv) and have the browser download it with javascript or D3.js?
- How to update selection with new data in D3?
- How to build a zoomable choropleth map with insets to handle discrete data in d3.v5?
- d3js - How to update an existing svg path in a simple d3 line chart with new data flowing through?
- Using crossfilter with dc.js and d3.js - how to get csv year data into date format?
- How can I update data with javascript d3?
- How to get data of parent node in d3.js
- D3 - how to deal with JSON data structures?
- How to handle layers with missing data points in d3.layout.stack()
- MultiBar chart with nvd3 / d3 only shows labels for every other tick on the x-axis. How can I get them all to show up?
More Query from same tag
- D3.js: circle color change on title mouseover doesn't work
- D3 seemingly updating wrong SVG element
- D3.js drag realtive to graph svg
- assigning d3 category colors to array of objects
- d3 check which dataset within function
- D3.js word cloud does not display without error message
- Add thinner arc for total in D3 Donut Chart
- Multiple D3 Graphs, Two Axis', No Category's
- d3 dynamic url based on array values
- angular-dimple dependency injection
- Convert JSON made by PHP "json_encode", into array to plot those values with D3
- Using the selection index in looped d3.js transition
- How to specify date format d3.js for x-axis
- Circles on a moving Line chart
- How to make SVG responsive in D3 with viewbox?
- d3.js color ordinal scale using wildcards?
- d3 zoom relative to viewport size
- d3.js heatmap not showing data correctly
- Draw links to a d3 circle pack layout
- D3 nodes overlapping
- Complex symbols within a single node in d3.js, where symbols depend on data
- Unable to click child element as parent is always in focus
- What is the data type of the 'data' argument in d3.request.get?
- Access a value in JSON when clicking a specific node in D3.js
- How to code a simple d3.js network graph using DIVs as nodes
- Creating a dropdown/select list from csv with d3 nest
- Transitioning innerRadius of svg.arc - D3.js
- Angular-nvD3 resizes chart on data change
- d3 parcoords lineWidth based on attribute
- Can't highlight text in foreign object when d3 drag is attached