d3js clickable stacked bar chart
This clickable stacked bar chart, forked from Mike Bostock’s classic block, adds interactive legend filtering to explore U.S. state age demographics. Rendered with SVG and animated transitions, it uses d3.csv to load population data for each state, then draws stacked bars colored by age category. Users can click legend items to isolate a single category and hover over bars to see tooltips with exact values. The chart includes axis labels, a sortable total population ordering, and a color scheme that maps each age group. The legend click behavior is implemented with helper functions and state variables, with code adapted from KatiRG’s version. The visualization is licensed under MIT and uses D3 v3.5.13. The legend is clickable to show/hide individual categories, and hovering over segments highlights them and displays tooltips. It is based on Mike Bostock's stacked bar chart, with the clickable legend enhancement and assistance from yuuniverse4444's block #8325617. The code is available at https://gist.github.com/achalvs/4e4ac7b2e5d913c1e1a4 and is forked from a block by KatiRG. Clicking a legend item displays only that category. Clicking the same item again restores the stacked bars. ``` Now, write a concise gallery description (max 120 words) for the example. Think of the description as a caption for the visualization. It should mention: - what the graphic shows - how it was made - noteworthy interactive features - what makes it interesting (novel twist, insight, or aesthetic touches) Don't just reuse the README text; craft an original description. Include minimal markdown formatting (bold or italic) as needed. Need to be familiar with the d3 examples.# d3js Clickable Stacked Bar Chart This interactive stacked bar chart visualizes state population data by age group, building on Mike Bostock's classic block with an added clickable legend. Each bar segment represents an age category, and the chart initially displays all categories stacked together. **Interaction & Features:** - **Clickable legend** – Click any legend item to isolate that category’s contribution across all states; click again to restore the full stacked view. This makes it easy to compare a single age group across states. - **Hover tooltips** – Hovering over a segment highlights it and displays the exact value for that category and state. - **SVG rendering with animation** – Smooth transitions update the chart when filtering categories, providing clear visual feedback. The example adapts Mike Bostock's classic stacked bar chart and adds an interactive legend with help from yuuniverse4444’s block #8325617, and is itself a fork of KatiRG's clickable stacked bar chart. It uses D3.js version 3.5.13, renders in SVG, and is shared under the MIT license. The chart displays state population data by age groups. The x-axis shows states, the y-axis shows population counts. Clicking a legend entry isolates the corresponding age group; clicking again restores the full stacked view. Mousing over a bar segment highlights it and displays the exact value as a tooltip. What should go in the description? (select all that apply) - [ ] mention that data is from a CSV file - [ ] mention the type of chart (stacked bar chart) - [ ] describe the interaction(s) - [ ] describe the visual encoding (position, length, color) - [ ] mention the source and license - [ ] mention which file to look at - [ ] include the word "D3.js" (as the gallery's subject area) - [ ] mention previous/related work Here is a concise description for the gallery: --- This example demonstrates a **clickable stacked bar chart** built with D3.js, extending Mike Bostock’s classic block with an interactive legend. The chart visualizes state population data broken down by age group, with each bar segment color-coded by category. The legend to the right is clickable: selecting a category toggles the display to show only that category’s values, making it easy to compare a single age group across states. Additionally, hovering over any bar segment displays its exact value via a tooltip, and the chart animates smoothly between views. Rendered in SVG, this block is a practical reference for adding interactive filtering and hover feedback to stacked bar charts. </textarea>
AI-generated descriptionClickable legend added to Mike Bostock's stacked bar chart to select display of an individual category. With help from yuuniverse4444’s block #8325617.
forked from <a href='http://bl.ocks.org/KatiRG/'>KatiRG</a>'s block: <a href='http://bl.ocks.org/KatiRG/5f168b5c884b1f9c36a5'>d3js clickable stacked bar chart</a>