Published
Edited
Jun 24, 2020
1 star
Insert cell
Insert cell
Insert cell
hatchedChart = {
const svg = d3.create("svg")
.attr("title", "Unlabelled chart")
.attr("class", "chart")
.attr("viewBox", [0, 0, width, height]);
const defs = svg
.append("defs");
const hatchSize = 3;
const hatchPattern = defs
.append("pattern")
.attr("id", "hatch")
.attr("width", hatchSize)
.attr("height", hatchSize)
.attr("patternTransform", `rotate(45)`)
.attr("patternUnits","userSpaceOnUse")
.append("rect")
.attr("width", hatchSize/2)
.attr("height", hatchSize)
.style("fill", activeColor);
svg.append("g")
.attr("class", "bars")
.selectAll("rect")
.data(data)
.join("rect")
.attr("role", "presentation")
.attr("class", "bar")
.attr("x", d => x(d.x))
.attr("y", d => y(d.y))
.attr("width", x.bandwidth())
.attr("height", d => y(0) - y(d.y))
.style("fill", "url(#hatch)");

svg.append("g")
.attr("class", "chart-by")
.call(chartBy)
return svg.node();
}
Insert cell
Insert cell
Insert cell
x = d3.scaleBand()
.domain(data.map(d => d.x))
.range([margin.left, width - margin.right])
.padding(0.1);
Insert cell
y = d3.scaleLinear()
.domain([0, d3.max(data, d => d.y)]).nice()
.range([height - margin.bottom, margin.top]);
Insert cell
chartBy = g => g
.attr("transform", `translate(${width}, ${height})`)
.append("text")
.attr("id", "source")
.attr("x", 0)
.attr("y", 0)
.attr("dy", "-0.5em")
.attr("text-anchor", "end")
.text('@DiDoesDigital');
Insert cell
Insert cell
margin = ({top: 24, right: 0, bottom: 48, left: 0})
Insert cell
Insert cell
barColor = "#766FAE"
Insert cell
inactiveColor = "#E6E5F0"
Insert cell
activeColor = "#534e7a"
Insert cell
Insert cell
Insert cell
accessibleDataTable = render_data_table(data, {caption: data.tableCaption, columns: data.slice[0], focusable: false})
Insert cell
Insert cell
data[0]
Insert cell
Insert cell
ss = require("simple-statistics@7")
Insert cell
d3 = require("d3@5", "d3-array@2.4")
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