Published
Edited
Apr 7, 2020
Insert cell
Insert cell
Insert cell
chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("width", width)
.attr("height", height);
var line = d3.line()
.x(function(d) { return xScale(new Date(d.date)); })
.y(function(d) { return yScale(d.value); });
forcasts.forEach((d,i) => {
svg.append('path').datum([].concat([result[i]], d.forcast))
.attr('d', line)
.attr('fill', 'none')
.attr('stroke', '#999');
});
svg.append('path').datum(result)
.attr('d', line)
.attr('fill', 'none')
.attr('stroke', 'black')
.attr('stroke-width', 2);

return svg.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3@5")
Insert cell
margin = ({top: 10, right: 20, bottom: 20, left: 30})
Insert cell
height = 300
Insert cell
width = 300
Insert cell
yScale = d3.scaleLinear()
.domain([0, maxValue])
.range([height, 0]);
Insert cell
xScale = d3.scaleTime()
.domain([new Date('1981-07'), new Date('1982-05')])
.range([0, width]);
Insert cell
maxValue = {
const maxResult = d3.max(result, d => d.value);
const maxForcast = d3.max([].concat(...forcasts.map(f => f.forcast)), d => d.value);
return d3.max([maxResult, maxForcast]);
}
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