Published
Edited
Sep 10, 2019
Insert cell
md`# line`
Insert cell
chart = {
const svg = d3.select(DOM.svg(width, height))
.style("width", "50%")
.style("height", "auto")
.style("font", "10px sans-serif");
svg.append("path")
.datum(data)
.attr("class", "line")
.attr("fill", "none")
.attr("stroke", "black")
.attr("stroke-width", "2")
.attr("d", line)
;

svg.append("path")
.datum(data)
.attr("class", "line")
.attr("fill", "none")
.attr("stroke", "black")
.attr("stroke-width", "2")
.attr("d", horLine)
;
return svg.node();
}
Insert cell
xScale = d3.scaleTime()
.domain([
d3.min(data, function(d) { return d.date; }),
d3.max(data, function(d) { return d.date; })
])
.range([0, width])
;
Insert cell
yScale = d3.scaleLinear()
.domain([0, d3.max(data, function(d) { return d.close; })])
.range([height, 0])
;
Insert cell
line = d3.line()
.x(function(d) { return xScale(d.date); })
.y(function(d) { return yScale(d.close); })
;
Insert cell
horLine = d3.line()
.x(function(d) { return xScale(d.date); })
.y(function(d) { return yScale(1514.68); })
;
Insert cell
rowConverter = function (d) {
return {
date: new Date(d.Datee),
close: parseFloat(d.Close)
}
}
Insert cell
width = 300
Insert cell
height = 300
Insert cell
data = d3.csv("https://gist.githubusercontent.com"
+ "/aaronxhill/baffd3e35d09430eb9ba6bd06b42d893"
+ "/raw/bea5e50fef3442eb52769f5302fe3f8ad774675e"
+ "/yahoosnp500.csv", d => { return rowConverter(d) })
//https://gist.github.com/aaronxhill/baffd3e35d09430eb9ba6bd06b42d893/raw/bea5e50fef3442eb52769f5302fe3f8ad774675e/yahoosnp500.csv
Insert cell
d3 = require("d3@5")
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