score:2
Accepted answer
The source of the issues you're seeing is that you have your text
and rect
elements grouped in g
elements. You need to handle enter, update and exit selections only for the g
elements. Everything else hangs off of that. This implies that you need to save the enter selection for the g
elements and then append the other elements to that.
The structure would look like this:
var barEnter = bar.enter().append('g');
barEnter.append("rect");
barEnter.append("text");
For the update selection:
bar.transition()...
bar.select("rect").transition()...
bar.select("text").transition()...
For the exit selection, you just need to remove the g
elements because that will also remove everything contained within them:
bar.exit().remove();
Complete demo here.
Source: stackoverflow.com
Related Query
- How do I implement d3's enter update exit pattern for an area chart with focus and context?
- How to use enter(), exit() and update with horizontal "stacked" chart
- How to use x and width in a bar chart with scaleTime?
- D3 chart can't update -- enter and exit property of selection both empty
- d3.js horizontal stacked bar chart with 2 vertical axes and tooltips
- d3 - Update Width and X for smooth transition in Horizontal Stacked Bar Chart
- How to update d3.js bar chart with new data
- How to create stacked row chart with one row with dc.js?
- d3.js stacked bar chart with positive and negative values
- how to zoom d3.js chart and reload data with greater granularity (in AJAX)
- How to create Stacked Line Chart D3, Multiple Y Axis and common X Axis
- NVD3.js: Stacked and grouped bar chart with two y-axis
- how to use .scale and .translate with d3.js?
- How to line up x axis on stacked bar chart with a line overlay in d3.js
- How to show values stacked bar chart utilizing dc.js and d3.js?
- Adapting diverging stacked bar chart to use general update pattern
- how to create a stacked bar chart with images in d3
- D3 How to update the chart after selection from drop down menu with new data
- d3 horizontal bar chart with background and max value of 100%
- How can I make a 100% stacked chart with nvd3?
- D3 v6: How to zoom stacked bar by selected segment to stretch only selected segment and shrink rest segments (and keep initial chart width)?
- How can I use D3.js "onClick" event with an nvd3 bar when zoomed in on chart data?
- Using d3-tip and CSS hover effect with d3 stacked bar chart
- D3 Object Constancy not working with key function. Enter and Update contain all elements every time
- How to use an exit selection on text with tspan
- How to use the filter method with the update pattern?
- D3js path update enter and exit
- How to use D3 to load csv, display table and style it with bootstrap in javascript
- How do you get JSON data and create a line chart with d3.js?
- How do I set the X values for a singled stacked horizontal bar chart using d3.js?
More Query from same tag
- Javascript d3.js reading local CSV file
- To set link label or tooltip for D3 Network chart
- Modifying data in non-DOM elements in D3?
- How to smoothly load 200MB data to browser for visualization?
- D3 Transitions between classes
- Force directed graphs in d3v4
- Javascript issue with rendering updated chart in D3
- Overflow not working when at end of the div
- d3 rotating wheel with fixed clip
- how to make real time multi line chart using d3 where data is from api in json format
- How to overlap multi-year dataset with NVD3
- Does D3 Support a Compositional (bottom-up) Approach?
- Why is the hover state behaviour removed?
- D3 force layout shall add nodes and links when clicking a node
- D3.js add link with label
- Transitioning a D3 V4 line graph into view
- Append element on d3 dragstart
- D3.v3 Brush Strange Behavior
- How to make an svg text with d3.js that flashes from black to white an back continuously?
- Javascript/JQuery for Datatables
- d3js Pie Chart – text labels
- Creating an endless horizontal axis with d3 v4
- Move the "Stacked/Grouped" selector on NVD3.js multiBarChart.js
- Change default locale date d3 v4
- Novice d3 stacked area graph
- D3.js highlight related nodes / links
- Calculating width to create continuous horizontal bar in D3.js
- Why do I get an attribute y="NaN" and height="NaN" in my d3.js stacked bar chart?
- D3 - Add dots in middle of lines between two points
- D3 Issues with time scale, calculating the position of items