Export Code
Connected
index.js
import {
select,
csv,
scaleLinear,
max,
scaleBand,
axisLeft,
axisBottom,
format
} from 'd3';

const titleText = 'Top 10 Most Populous Countries';
const xAxisLabelText = 'Population';

const svg = select('svg');

const width = +svg.attr('width');
const height = +svg.attr('height');

const render = data => {
const xValue = d => d['population'];
const yValue = d => d.country;
const margin = { top: 50, right: 40, bottom: 77, left: 180 };
const innerWidth = width - margin.left - margin.right;
const innerHeight = height - margin.top - margin.bottom;
const xScale = scaleLinear()
.domain([0, max(data, xValue)])
.range([0, innerWidth]);
const yScale = scaleBand()
.domain(data.map(yValue))
.range([0, innerHeight])
.padding(0.1);
const g = svg.append('g')

Making a Bar Chart

Curran Kelleher

Last edited Dec 28, 2019
Created on Dec 19, 2019
Forked from Customizing Axes

This bar chart shows population of the top 10 most populous countries. The data comes from the year 2018 estimate in United Nations: World Population Prospects 2017. It also demonstrates customization of D3 axes.

MIT Licensed