React + D3 + useData Viz Starter
✓ Published4🌍 Public
This example demonstrates a minimal React + D3 starter template for building SVG visualizations with a reusable margin convention. It fetches Hepatitis C data from a CSV URL using a custom `useData` hook built with `useEffect` and `useState`, loading via D3’s `csv` method. A `VizContainer` component abstracts the SVG and group elements, translating the inner group by the specified margins and conditionally rendering gray rectangles to visualize the chart area. The code relies on CDN-loaded React 16, ReactDOM, and D3 v6, with dimensions hardcoded at 960 by 500 pixels.
AI-generated descriptionBoilerplate code for a React + D3 visualization with:
- CDN links for React, ReactDOM, and D3
- Basic React boilerplate
- Variables for dimensions and margins
useDatahook to fetch a CSV URL.VizContainercomponent that:- Abstracts SVG/group container elements
- Follows the margin convention
- Show the margins, which can be easily removed by deleting the
showMargins={true} prop
MIT Licensed