score:1
Accepted answer
You could loop through the values
array in each top-level object and keep a running total of value
, which becomes y0
for each <rect>
. y1
then is y0 + value
.
Then bind each top-level object to a <g>
tag representing the entire stack, translate that to the appropriate x
position (assuming bars are vertical), and append <rect>
s to each <g>
with the values
prop as data. Set the height
and y
position of the rect according to where in the stack it belongs. That might look like:
var groups = d3.selectAll("g")
.data(nested)
.enter().append("g");
groups.attr("transform","translate...");
var rects = groups.selectAll("rect")
.data(function(d) { return d.values })
.enter().append("rect");
rects
.attr("width",...)
.attr("height",...)
.attr("y",...)
Source: stackoverflow.com
Related Query
- Proper data structure for D3 stacked bar chart
- Converting data structure of a JSON array for stacked bar chart
- Prepare nested JSON data for D3 stacked bar chart
- Is this JSON structure suitable for a stacked bar chart using d3.js?
- sort data for d3 stacked bar chart
- Reshape data for D3 stacked bar chart
- d3.js - group 2 data values in a stacked bar chart
- d3 v4 nested data and stacked bar chart
- How to modify axis labels in d3 for a stacked bar chart when the axis labels are mapped as part of the scale's domain
- d3 show labels only for ticks with data in a bar chart
- Javascript manipulate data into array of object for d3 stacked chart
- D3 V4 Rect bind data in stacked bar chart
- Stacked Bar Chart with Time Series Data
- Filtering in stacked bar chart using d3 v3.js by changing data on input selection
- d3.js - How to do data mapping and filter for Stacked Bar graph
- Transition for grouped bar chart in d3 when updating the data values
- How to add live data to stacked bar chart
- How do I set the X values for a singled stacked horizontal bar chart using d3.js?
- How to use log scale to show proper stacked bar chart using d3 JS?
- d3.js Stacked Bar Chart working for one dataset but not the other
- Proper data structure for d3 nodes
- How to create a d3 stacked bar chart that only iterates through columns 1 and 2 of data file?
- how to update text added in dimple.js stacked bar chart on data updation
- d3 setting minimum height for stacked bar chart
- Regarding D3 stacked bar chart structure
- D3 horizontal stacked bar chart add and remove data
- D3 - stacked bar chart shows wrong data in the chart
- how to access specific data in an array using D3.js v5 for a stacked bar graph tooltip
- How to place legends for stacked bar chart underneath in d3.js
- Create Stacked Bar chart for Timeseries X axis using C3.js
More Query from same tag
- Angular D3js links not are displaying
- How to add legend to an aster plot d3 js?
- D3 Ticks on x axis wrong
- Tooltip not showing up d3.js
- d3.extent() on object keys (not values)
- d3 append copy of g element on click to separate div
- Please advice D3.js for CSV data import(Part2)
- Transition font-size on Chrome after zoom in
- How do I plot points on a map using D3.js?
- Topojson properties field, how do I show all proprieties in d3.js
- How to get position of empty SVG group?
- D3 mouseover text positioning
- d3js - Sortable Group Bar Chart
- Create a choropleth map of all cities in world in react js
- Variable in Script dependent upon user input of Text Field
- Trace path with DOM object
- D3.js not defined, express serving up static files
- D3 force layout from CSV with multiple edges per row
- Date manipulations in D3.js
- Proper way to integrate JS in Angular
- unusual black shapes in d3 choropleth
- Saving a SVG element as PNG on local system
- SVG path stroke-dasharray transition works backwards in some browsers -d3js
- Manipulate SVG with javascript?
- display data from csv file into BarGraph using d3.js
- D3 V4 Hierarchical Edge Bundling port from v3
- Drawing circles with D3 from TSV file
- Convert dc.js chart to pdf
- new array from csv data
- Removing elements by class on scroll