Skip to main content
100%

Making a horizontal bar chart

✓ Published0🌍 Public
Ddeepak jangid
Last edited May 30, 2020
Created on May 23, 2020
Forked from Hello VizHub

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 description

Creating a horizontal bar chat.

  1. Representing a data table in javascript.
  2. Creating rectangles for each row.
  3. Using linear and band scales.
  4. The Margin Convention.
  5. Adding Axes and Brand names.
  6. Fill the color in rectangle, if(val_1 >= mark_val) 'green' else 'red'.
  7. Add small vertical line representing mark_val data.
MIT Licensed

Similar vizzes