score:1
On line 239—
bar.append("rect")
—you probably meant .select
, not .append
.
Your current code is appending a new set of <rect>
s every time the chart updates, and the old ones aren't aligned right.
Note the increasing size of the d3 selection that I'm running in the dev tools on the right.
When fixed, it looks like this:
score:1
Editing lines 232 - 242 in index.html
so that bar
was not called twice fixed the problem, as well as changing .append
to .select
.
Previous code:
bar.data(newhistdata)
.transition()
.duration(1000)
.attr("transform", function(d,i) {
return "translate(" + x2(i * binsize + minbin) + "," + y(d.numFlips) + ")";
});
bar.append("rect")
.attr("x", x(binmargin))
.attr("width", x(binsize - 2 * binmargin))
.attr("height", function(d) { return height - y(d.numFlips); });
Edited:
bar.data(newhistdata)
.transition()
.duration(1000)
.attr("transform", function(d,i) {
return "translate(" + x2(i * binsize + minbin) + "," + y(d.numFlips) + ")";
})
.select('rect')
.attr('x', x(binmargin))
.attr("width", x(binsize - 2 * binmargin))
.attr("height", function(d) { return height - y(d.numFlips); });
Source: stackoverflow.com
Related Query
- D3.JS Histogram: error aligning bars when updating data
- NVD3 - uneven ticks when updating data
- Updating D3 histogram as data comes in
- D3 + React Native - Data point value not updating when X position changes
- Transition for grouped bar chart in d3 when updating the data values
- How to keep circles inside the svg when updating data in bubble chart
- Error parsing data when drawing d3 line chart
- D3 - V3: Scope error when using data loaded from a json file
- Click event not updating in React/D3 when data is updated
- Error when passing JSON data to d3.json
- can't get .exit() and .enter() to work properly when updating data in d3.js
- Error when drawing a d3.js line with no data
- D3 v4 graph not updating bars - but appending new axis data
- Markers not removed when updating data on a Dimple area chart
- Histogram bars disappeared when added a min value to the y domain - D3
- Updating links on a force directed graph from dynamic json data
- How to update elements of D3 force layout when the underlying data changes
- D3.js time scale: nicely-spaced ticks at minute intervals when data is in seconds?
- Placing a circle over a sparkline when the user changes the ordering of the data
- Calling a function once when data enters in d3
- TypeScript error when using d3.timeFormat in axis.tickFormat()
- No 'Access-Control-Allow-Origin' header is present on the requested resource Error when loading JSON file
- d3 - Change text label when data updates
- D3 - How to update force simulation when data values change
- Updating the data of a pack layout from JSON call and redrawing
- Updating dc.js data and reapplying original filters
- Avoid data caching when using d3.text
- d3JS: Plot lower-density data version of a large data set when zoomed out on line/area chart
- transition when adding new data to d3 streamgraph
- D3 Data Binding - When to put brackets around data
More Query from same tag
- Remove Text from Nodes in d3
- Add background to svg polyline
- dc Line chart not highlighting properly in Firefox on legend hover
- How to increase vertical margins of nodes of clustered dendrogram
- Migrating javascript nested function to typescript gets error
- Icon not displaying correctly
- Delete a line when ticks are clicked - d3js
- How can I add in Data Labels to my D3 bar chart?
- d3 treemap make each rectangle size represent it's value
- D3 Pie Chart Update, IV in while loop not working well - why?
- D3 Sliders - Retrieving & Showing Values
- Rotate label text on D3
- How can I add an image as the fill for a circle dynamically in javascript using d3
- D3 - Stacked bar chart, show all values in tooltip
- d3.js NVD3 trigger tooltip manually
- get all features properties in d3
- Brush and transition coexist
- D3 world-50m.json projection filling incorrectly
- Responsive Donut Chart d3
- Add Spacing and Interactivity to D3 Vers 6 Stacked Bar Chart
- Converting stroked path to shape with javascript
- Invalid regular expression in d3.v5
- d3 Update Example in Typescript - Scoping Issue?
- Change height and width of the path tag in SVG Image
- Convert Curve path to straight path using jquery with animation
- How to change opacity on second click?
- D3 is attempting to set attributes of SVG as NaN and I can't figure out why
- d3 bar chart transition from csv
- updating area chart
- Uncaught TypeError: d3plus.Pie is not a constructor