Stacked Bar Chart
This stacked bar chart displays energy consumption across different building system types for three cases, with each bar segmented and color-coded by category. The visualization uses D3 v3’s `d3.scale.ordinal` for the x-axis and color encoding, `d3.scale.linear` for the y-axis, and `d3.svg.axis` for tick labels formatted with `d3.format`. Data is loaded from a CSV via `d3.csv`, and the bars are drawn as SVG `rect` elements grouped by case. A custom legend maps colors to system names, and y-domains are computed using `d3.max`.
AI-generated descriptionThis stacked bar chart is constructed from a CSV file storing the populations of different states by age group. The chart employs conventional margins and a number of D3 features:
- d3.csv - load and parse data
- d3.scale.ordinal - x-position encoding and color encoding
- d3.scale.linear - y-position encoding
- d3.format - SI prefix formatting (e.g., “10M” for 10,000,000)
- d3.max - compute domains
- d3.keys - compute column names
- d3.svg.axis - display axes
This example doesn’t use d3.layout.stack because it’s easy to just stack each state independently via array.forEach. Here, it makes sense to group the rects by state (column), rather than grouping by age group (series), as you do with a stacked area chart.
forked from <a href='http://bl.ocks.org/boyansky/'>boyansky</a>'s block: <a href='http://bl.ocks.org/boyansky/a189ec196fe8e049e41f'>Stacked Bar Chart</a>