Skip to main content
Public

Share visualization

Loading preview…

Creating SVG Bar Chart

vizhub.com

Shared links may look like this on X, LinkedIn, Slack, and Discord.

Before sharing, review the publishing checklist.

Choose how to deliver this visualization

LinkedIn caption

LinkedIn may not keep text supplied by the share sheet. Copy the caption and paste it into the post if needed. You can tag the VizHub company page when posting.

More options

Embed on a websiteCopy iframe embed code
Download & exportPNG, HTML, source ZIP

Creating SVG Bar Chart

2
DDasbach.EJ
Last edited Apr 18, 2021
Created on Apr 18, 2021

This example demonstrates a simple SVG bar chart built with D3 version 6. It generates a random dataset of ten values using `d3.range` and `Math.random`, then renders each value as a `rect` element, with its height and vertical position proportional to the data. The chart also labels each bar with a `text` element showing its value. The code uses D3’s `select`, `selectAll`, `data`, and `enter` methods to bind data and create the SVG elements, with bars colored using an RGB fill based on each value.

AI-generated description

A demonstration of how to start using D3 version 6.

Comments

Sign in to join the discussion.

MIT Licensed