score:1
You are dealing with a nested selection. First, you don't need to re-bind the data to the nested element, it's automatically passed. Second, you aren't handling the enter, update and exit selections properly. Re-factored it would look like this:
// update selection
var p = d3.select("body")
.selectAll(".lol")
.data(d3.stack().keys(keys)(data));
// those being removed
p.exit().remove();
// those entering
var pEnter = p.enter()
.append("p")
.attr("class", "lol");
// append a span to those entering
pEnter.append("span");
// this is update + enter
p = pEnter.merge(p);
// update the update + enter selection's sub-selection
p.select("span").html(function(d) { return d });
Updated fiddle.
Source: stackoverflow.com
Related Query
- d3.js data not bound the first time
- Create a padding for the first and last data points using a time scale
- d3.js + dynamic HTML - first data point not processed & .append appends to the wrong place
- Why is the first element in my d3 data not being updated?
- Function generating HTML table does not create <td> elements the first time
- d3.data skipping the first row of data
- Data points and ticks in the scaleBand axis are not aligned
- Looping through data attributes to create 4 separate bar charts... why are there "phantom" data elements being bound to the xAxis?
- How do I get D3 Data Driven Document to display a moment.js datetime in the correct time zone?
- Visualization data inserted in the webpage is not properly indented and not appearing at desired position
- Crossfiltering of JSON data by the most recent time
- the data is changed, but reloading does not fetch new data, D3
- D3 transition from stacked bar to bar chart only works the first time
- Simple circle animation is only displayed the first time
- My D3.js code is not showing seconds in the time axis?
- D3.js version3 scale.ordinal() not reading in my data the way I would like
- Chart is not showing the data array of objects
- Data not being bound to a selection in d3
- d3.js data not refreshing upon change in the file
- Load and display data with condition, but the condition is not met
- Axis is not displaying the first element in the domain
- d3 - enter - appends too many elements, as if data is not bound
- Missing data after adding the time range
- d3js:The xaxis time is not showing the complete date value
- d3.js circle plotting does not working properly while trying to load after first time
- Data bound to children is not updated with new data
- Updating only those SVG elements where the underlying bound data has been modified
- Trying to make reusable javascript function, but the data is not returning
- D3 - not all children nodes are shown at the same time
- Drawing a line using d3 is not visible when all data items are the same
More Query from same tag
- Can I use zoom.translateBy to set an initial pan?
- D3 heat map - Colour scale only showing one colour
- D3 force directed graph direction
- How to expand a data scale on NVD3 line chart
- How can I add a transition effect to a radius increase on a circle?
- Multi Segments in one segment in a donut chart?
- d3js - adding a speech-bubble like tooltip?
- D3 polygon projection is wrong
- How to create Sankey Diagrams with curved node endpoints?
- enlarge / animate map or change viewBox
- How do I position subgroups of small multiples together on the page?
- Why does d3.json return "null"?
- Factoring out attributes for reuse in D3 transition
- Create infinite parallel pattern
- Embedded svg isn't scaled correctly
- Overflow a circle outside the bounds
- Issue when trying to retrieve individual values from a csv file
- Mouseover event not triggered when data updated in Chrome
- How i can draw additional x-axis on point 0 of y-axis in d3 graph
- How to add svg on top of another svg in d3,js
- Using d3 to visualize rapid fire 'clicks'
- Re-render HTML after zoom using Dagre d3
- d3js: How to pass button id to onclick callback function
- d3.csv unable to go up one directory
- How to apply a pattern for a D3 bar chart?
- Problems with interactivity
- Error: Cannot read properties of undefined (reading 'nativeElement'), and barchart did not show
- D3: What projection am I using? / How to simplify with a null projection?
- Iterate through Key/Values in D3 graph for line chart
- Rotating a symbolTriangle shape in D3