Public
Edited
Jul 10, 2023
Insert cell
Insert cell
chart = {
const svg = d3.select(DOM.svg(width, height));

svg.append('g').call(xAxis);

svg.append('g').call(yAxis);

svg
.append('g')
.attr('fill', '#006A4E')
.attr('opacity', 0.7)
.selectAll('circle')
.data(all_data)
.join('circle')
.attr('r', 5)
.attr('cx', d => outerpadding + x(new Date(d[0])))
.attr('cy', d => y(d[1]))
.append('title')
.text(d => `Pnt ${d[0]}`);

svg
.append("g")
.attr("fill", "gray")
.attr('opacity', 0.3)
.selectAll("rect")
.data(all_data)
.join("rect")
.attr('x', d => outerpadding + x(new Date(d[0]))-x_band.bandwidth()/2)
// .attr("x", d => x_band(d[0]))
.attr("y", d => y(d[2]))
.attr("height", d => y(0) - y(d[2]))
.attr("width", x_band.bandwidth())
.append('title')
.text(d => `Rect ${d[0]}`);

return svg.node();
}
Insert cell
outerpadding = x_band(x_band.domain().shift()) - x_band.range()[0]
Insert cell
Insert cell
Insert cell
y = d3
.scaleLinear()
.domain([0, 3])
.range([height - margin.bottom, margin.top])
Insert cell
x = d3
.scaleTime()
.domain([new Date("2019-01-01"), new Date("2019-02-01")])
.range([margin.left, width - margin.right])
Insert cell
x_band = d3
.scaleBand()
.domain(all_data.map(d => d[0]))
.range([margin.left, width - margin.right])
.padding(0.3)
Insert cell
xAxis = g =>
g
.attr("transform", `translate(${outerpadding},${height - margin.bottom})`)
.call(d3.axisBottom(x))
Insert cell
yAxis = g =>
g.attr("transform", `translate(${margin.left},0)`).call(d3.axisLeft(y))
Insert cell
all_data = d3.timeDay
.range(new Date("2019-01-01"), new Date("2019-02-01"))
.map(d => [d, 0.05, 2])
Insert cell
formatTime = d3.timeFormat("%Y-%m-%d")
Insert cell
d3 = require("d3@5")
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