Public
Edited
May 3, 2023
Insert cell
Insert cell
Insert cell
chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

svg.append(legend)
.attr("transform", "translate(670,200)");

svg.append("g")
.selectAll("path")
.data(topojson.feature(polygons, polygons.objects.NJCounties).features)
.join("path")
.attr("fill", d => color(data.get(d.properties[idAttribute])))
.attr("stroke", "black")
.attr("d", path)
.append("title")
.text(d => `${d.properties[idAttribute]}, ${format(data.get(d.properties[idAttribute]))}`);

return svg.node();
}
Insert cell
Insert cell
labels = ["low", "med", "high"]
Insert cell
n = Math.floor(Math.sqrt(colors.length))
Insert cell
x = d3.scaleQuantile(Array.from(data.values(), d => d[0]), d3.range(n))
Insert cell
y = d3.scaleQuantile(Array.from(data.values(), d => d[1]), d3.range(n))
Insert cell
path = d3.geoPath().projection(projection)
Insert cell
//Rotate the map sets the longitude of origin for our UTM projection.
projection = d3.geoTransverseMercator().rotate([87,0]).fitExtent([[10, 10], [width, height]], polygon_features);
Insert cell
polygon_features = topojson.feature(polygons, polygons.objects.NJCounties)
Insert cell
data = Object.assign(new Map(d3.csvParse(await FileAttachment("NJpopDenNumSites.csv").text(), ({COUNTY, SQ_MILES, POP2010, NUMSITES}) => [COUNTY, [POP2010/SQ_MILES, NUMSITES]])), {title: ["Pop Density", "Contaminated Sites"]})
Insert cell
idAttribute = "COUNTY"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
formatNum = d3.format(".1f")
Insert cell
Insert cell
Insert cell
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