score:1
Accepted answer
The issue was with the parsing of the data every time the window was resized.
As the date within the data is parsed the first time, calling parseDate(d.date)
will fail on every other call as it's already been parsed to a valid date. Do you get it?
Hence, moving the parsing code so that it's executed just once:
// parse data just once
data.forEach(function(d) {
d.date = parseDate(d.date);
d.value = +d.value;
});
Fiddle link: https://jsfiddle.net/a5rqt0L1/
Suggestion: I feel this isn't the right way to make a responsive chart i.e. removing SVG and re-appending to the body with all the configuration done multiple times. Here's how I'd do it:
- Parse the data, append svg with initial height and width, append X, Y axes just once but move
drawBars
(to draw the actual bars) to a separate function that will use d3's own enter, exit and update selection logic. - On window resize, just change the SVG's height and width, re-render the axes by
.call(xAxis)...
and just call thedrawBars
function.
Hope this helps.
Source: stackoverflow.com
Related Query
- D3 line chart axis text labels in multi line
- dc.js Series Chart multi line
- Multi Line Ordinal d3 chart
- d3: tooltips on multi series line chart at each line when mouse hover event
- D3 multi line chart - strange animation
- simple multi line chart with D3
- d3.js multi y-axis line chart
- D3 - Single and Multi Line chart tooltips
- Legend in Multi line chart - d3
- Responsive line chart with transitions using d3
- How to make a D3 Line Chart Responsive
- Multi line chart using d3 and json in a nvd3 structure
- SVG Legend for multi line chart d3 v6
- D3 Multi Line Chart Not Displaying Properly With X Axis Value
- Responsive D3 Donut Chart on Screen Resize
- Error displaying dots on a multi series line - dots chart
- D3.JS - Line chart - responsive - can't find a way to update Line's x-values
- Fill same line color in to circle on Multi Line chart when mouse over and remove color from circle when mouse out
- Color overlapped portions of multi line chart
- D3 Multi Series Line chart not working with correct xAxis values
- D3 v4 Multi line chart Brush Issue NaN when moving brush
- dc.js multi line series chart filtering
- Using D3, I am trying to add and remove lines from a multi line chart when the legend is clicked
- On making chart responsive the x,y axis line disappears
- Creating scatter points on a multi line chart
- d3.js - Multi series line chart tool tip issue
- multi line chart nvd3 not shown properly
- Animated Path multi series line chart in D3.Js
- D3 Multi Series Line Chart with Clickable Legend
- Recreate D3 Multi-Line Chart on Resize (responsive)
More Query from same tag
- d3js tree chart not fitting on canvas
- d3.js v5 : Unable to get data points to show on map of US
- Update table with key-value pair array as data
- Disable brush on range chart before selecting a scale from the dropdown/on page load(dc.js,d3.js)
- I want to update the data on this d3.js bar chart by clicking a button. (onclick)
- Can someone explain this Javascript pattern found in D3s Pie Layout?
- How to use d3.js colorScale to change color based on string values rather than numeric values?
- Trouble with getting a bubble chart working in d3
- Cannot add capitals to geojson world map
- d3.js wrong boundingbox-values after using a transition
- Error with .compose using dc.js
- How to select and deselect a svg line and change its color on selection and deselection using d3.js and javascript , jquery?
- d3.json not parsing my JSON correctly?
- Transition on labels in d3 pie/donut chart
- Create dataset from array of numbers with d3.js
- How to initiate zoomability in a Sunburst with selection from dropdown
- D3 version 6.1 focus + context + tooltip
- C3 Extent not working as expected
- Extend axis on c3.js
- D3 Geojson map won't display
- Prevent d3 brush from firing a click event
- d3 choropleth map javascript switching json data
- How to add conditional transitions?
- How to activate another line when clicking on another in d3.js
- Passing a CSV/TSV file to D3 using MVC
- Plotting points on a map with D3
- Angular and d3.js cannot access class field
- How to display the value for the final tick on axis in D3?
- Accessing Lines Chord Diagram D3
- Adding svg element with D3 in knockout and breeze