Published
Edited
Sep 29, 2021
1 fork
5 stars
Insert cell
Insert cell
regression = d3.regressionPoly()
.order(4)
.x(d => d.date)
.y(d => d.value);
Insert cell
regressionOutput = regression(data);
Insert cell
Insert cell
Insert cell
Insert cell
html`
<style>
.tick line {
stroke: #eee;
}
.domain {
stroke: #eee;
}
</style>
`
Insert cell
Insert cell
margin = ({left: 26, right: 3, top: 3, bottom: 17});
Insert cell
innerWidth = width - margin.left - margin.right;
Insert cell
height = Math.max(350, width * 9 / 16);
Insert cell
innerHeight = height - margin.top - margin.bottom;
Insert cell
Insert cell
xAxis = d3.axisBottom(x)
.tickSize(innerHeight + 6);
Insert cell
yAxis = d3.axisLeft(y)
.tickSize(innerWidth + 6)
Insert cell
Insert cell
x = d3.scaleTime()
.domain(d3.extent(data, d => d.date))
.range([0, innerWidth]);
Insert cell
y = d3.scaleLinear()
.domain([310, 400])
.range([innerHeight, 0]);
Insert cell
Insert cell
data = {
const data = await FileAttachment("regression_test.csv").csv();
// Convert types
data.forEach(d => {
d.value = +d.value;
const [date, time] = d.date.split(" ");
const [hh, mn, ss] = time.split(":").map(d => +d);
const [yyyy, mo, dd] = date.split("-").map(d => +d);
d.date = new Date(yyyy, mo - 1, dd, hh, mn, ss);
return d;
});
return data;
}
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more