Public
Edited
May 28, 2023
Insert cell
d3.select('#bubble-chart')
// remove the loading text from the container
.text(null)
.datum(fd)
.call(chart)
Insert cell
chart = fc
.chartCartesian(d3.scaleLog(), d3.scaleLinear())
.xDomain(fc.extentLinear().accessors([d => d.income])(fd))
.yDomain(fc.extentLinear().accessors([d => d.lifeExpectancy])(fd))
.chartLabel('The Wealth & Health of Nations')
.xLabel('Income (dollars)')
.yLabel('Life expectancy (years)')
.xTicks(2, d3.format(',d'))
.yOrient('left')
.svgPlotArea(pointSeries)
.decorate(selection => {
// append an svg for the d3-legend
selection
.enter()
.append('d3fc-svg')
.attr('class', 'legend');

// render the legend
selection
.select('.legend')
.select('svg')
.call(legend);
});
Insert cell
pointSeries = fc
.seriesSvgPoint()
.crossValue(d => d.income)
.mainValue(d => d.lifeExpectancy)
.size(d => size(d.population))
.decorate(sel => {
sel.enter().attr('fill', d => color(d.region));
});
Insert cell
size = d3
.scaleLinear()
.range([20, 800])
.domain(fc.extentLinear().accessors([d => d.population])(fd));
Insert cell
legend = d3.legendColor().scale(color)
Insert cell
color = d3.scaleOrdinal(d3.schemeCategory10).domain(regions.values())
Insert cell
regions = new Set(fd.map(d => d.region))
Insert cell

fd.forEach(d => {
d.income = Number(d.income);
d.population = Number(d.population);
d.lifeExpectancy = Number(d.lifeExpectancy);
});
Insert cell
healthWealth = FileAttachment("health-wealth.json").json()
Insert cell
d3 = require("d3@latest")
Insert cell
fc = require("d3fc@latest")
Insert cell
indexRollup = require("d3-svg-legend@2.25.6")
Insert cell
d3.legendColor = indexRollup.legendColor;
Insert cell
fd = FileAttachment("health-wealth.json").json()
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more