Skip to main content
100%

use the scaleLinear() to draw barchart2

✓ Published1🌍 Public
Ssgzzhinde
Last edited Jan 12, 2021
Created on Jan 12, 2021

This example demonstrates how to draw a simple bar chart using D3.js version 5’s `scaleLinear()` function to map data values to pixel widths. A hardcoded array of five numeric values is transformed into green rectangular bars, each with a fixed height and spacing, rendered as SVG within a React-equipped HTML page. The code explicitly creates a linear scale with a domain from zero to the maximum data value and a range of 0 to 400 pixels, then applies that scale to each rectangle’s width attribute via D3’s data join and selection methods.

AI-generated description

A bare minimum HTML page demonstrating use of CSS and JavaScript.

See also React Starter.

MIT Licensed

Similar vizzes