Making a horizontal bar chart
✓ Published0🌍 Public
This example shows a horizontal bar chart comparing two values (`val_1` and `val_2`) for five beverage brands, with each bar colored green or red based on whether `val_1` meets a threshold (`mark_val`), and a vertical black line marking that threshold. Built with D3 v5, it uses `scaleLinear` and `scaleBand` to map data to coordinates, appends rectangles and lines to an SVG, and animates a rotation of the chart’s coordinate system. Data is loaded from a CSV file via `csv()` and parsed into numeric fields.
AI-generated descriptionCreating a horizontal bar chat.
- Representing a data table in javascript.
- Creating rectangles for each row.
- Using linear and band scales.
- The Margin Convention.
- Adding Axes and Brand names.
- Fill the color in rectangle, if(val_1 >= mark_val) 'green' else 'red'.
- Add small vertical line representing mark_val data.
MIT Licensed