score:1
A few minor things were missing/incorrect:
The group (
<g>
) containing the bars was being transformed incorrectly (I'm guessing you missed this while changing from vertical stacked to horizontal) i.e. the following line.attr("transform", function(d) { return "translate(" + y(d.rooms) + ",0)"; });
translates the bar groups from the left and the y position would be 0 and hence the overlap. I've changed that to this:
.attr("transform", function(d) { return "translate(0, " + y(d.rooms) + ")"; });
The rects' x value is changed from
x(d.y1)
tox(d.y0)
(might be a typo)bar_enter.append("rect") .attr("height", y.bandwidth()) .attr("x", function(d) { return x(d.y0); })
Axis padding was missing for the scaleBand(). I've added that (check docs for more info)
var y = d3.scaleBand() .rangeRound([height, 0]).padding(0.1);
Reset the margins to adapt to the SVG dimensions:
var margin = {top: 10, right: 60, bottom: 60, left: 50},
Combining all of the above, here's a fork of your codepen:
HORIZONTAL STACKED BAR CHART DEMO
Hope this helps.
Source: stackoverflow.com
Related Query
- Convert vertical stacked bar to horizontal stacked bar D3.js v4
- D3.js Stacked Bar Chart, from vertical to horizontal
- D3 Chart version 4 Normalized Stacked Bar Chart from vertical to horizontal
- d3.js horizontal stacked bar chart with 2 vertical axes and tooltips
- Changing the orientation of the Stacked bar Chart from Vertical to Horizontal in D3
- change Vertical stacked bar to horizontal stacked Bar d3.js
- D3js - change Vertical bar chart to Horizontal bar chart
- D3 updating a vertical stacked bar chart
- Single horizontal stacked bar
- Making an existing vertical bar chart horizontal
- Load data from csv but represent it differently D3 - horizontal stacked bar
- How do I set the X values for a singled stacked horizontal bar chart using d3.js?
- Vertical align long text in yAxis for horizontal bar chart
- Adjust text inside the bar of a d3 horizontal stacked bar
- Horizontal Stacked Bar Chart with Two Y Axis Issues
- Adding a horizontal and vertical scroll bar for d3-2way-tree for multilevel tree
- D3 horizontal stacked bar chart add and remove data
- How to dynamically render horizontal stacked bar charts in D3
- D3JS Bar Chart Tooltip, translating from vertical to horizontal
- Text on top of d3 vertical stacked bar chart
- how to display bar values in horizontal stacked bar chart
- d3js - Stacked Bar Chart in Horizontal Axis - How do I set x so the bars are seperated?
- How to change Horizontal bar chart to vertical bar chart in D3 v4
- d3js : Stacked Horizontal Bar : How to split categories into bars
- D3 Horizontal Stacked Bar Chart with Lines
- D3 fill for a horizontal stacked bar chart in Angular with typeScript: .attr("fill", ..) gets error "No overload matches this call" in VSC
- D3(v4/v5): Convert Vertical Violin Chart into horizontal Violin Chart
- d3 - Update Width and X for smooth transition in Horizontal Stacked Bar Chart
- Horizontal Bar chart with vertical line is possible or not in D3
- Stacked Vertical Bar Chart Labeling - D3.js
More Query from same tag
- Incomplete graph in d3.js using json
- D3 bubbles force layout animation
- d3 - Bar Chart overlapping my text, how can I reduce the domain so it doesn't?
- crossfilter.js multidimensional "dimension"
- d3.csv show "XMLHttpRequest cannot load " error
- D3 Angular chart axis labels
- Javascript error "Unexpected strict mode reserved word" while using d3.js with apache codrova
- Convert a d3 chart to load data from json inside a variable
- dc.js: ReduceSum with multiple CSVs
- Sunburst partition data overwritten by second sunburst on same page
- Removing items with a transition prevents them from being added during that period
- How can I clip a trendline on a d3 scatterplot chart?
- View data in graph from rails
- How are enter() and exit() detecting updated data in D3?
- Using External json file for creating bubble chart using d3js
- How to entirely remove a d3 forceSimulation and its drag handers
- nvd3 positive and negative value for same timestamp
- why does 'on mouse...' function strangely
- node labelling not working d3 v5
- d3 v4 Stacked to Grouped Bar Chart from CSV
- d3.js display image as circle
- d3.js: How to get event information for drag
- Simplest way of integrating Angular-created elements with D3
- Time Parse Error in d3.js?
- d3.nest with multiple columns
- Ticks should correspond to Date data points in D3.js
- Dimple.JS Animate line series animation
- how to get a parentNode's index i using d3.js
- .on('mouseover', d => ..) does not provide same `d` as .attr('foo', d => ..)
- Can't add anything to my d3 bar graph