Public
Edited
Dec 27, 2021
2 forks
6 stars
Insert cell
Insert cell
Insert cell
<svg width="950" height="60">
<!-- Dashes and gaps of the same size -->
<line x1="0" y1="10" x2="700" y2="10" stroke="black" stroke-dasharray="1" stroke-width="5"/></line>
<line x1="0" y1="20" x2="700" y2="20" stroke="black" stroke-dasharray="3" stroke-width="5"/></line>
<line x1="0" y1="30" x2="700" y2="30" stroke="black" stroke-dasharray="5" stroke-width="5"/></line>
<line x1="0" y1="40" x2="700" y2="40" stroke="black" stroke-dasharray="10" stroke-width="5"/></line>
<line x1="0" y1="50" x2="700" y2="50" stroke="black" stroke-dasharray="15" stroke-width="5"/></line>
</svg>
Insert cell
Insert cell
<svg width="950" height="60">
<!-- Dashes and gaps of the same size -->
<line x1="0" y1="10" x2="700" y2="10" stroke="black" stroke-dasharray="700 700" stroke-width="5"/></line>
<line x1="0" y1="20" x2="700" y2="20" stroke="black" stroke-dasharray="3 10" stroke-width="5"/></line>
<line x1="0" y1="30" x2="700" y2="30" stroke="black" stroke-dasharray="3 15" stroke-width="5"/></line>
<line x1="0" y1="40" x2="700" y2="40" stroke="black" stroke-dasharray="3 50" stroke-width="5"/></line>
<line x1="0" y1="50" x2="700" y2="50" stroke="black" stroke-dasharray="3 100" stroke-width="5"/></line>
</svg>
Insert cell
Insert cell
chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

svg.append("path")
.datum(data)
.attr("class", "line")
.attr("d", line)
.transition()
.duration(5000)
.ease(d3.easeLinear)
.attrTween("stroke-dasharray", function() {
const length = this.getTotalLength();
return d3.interpolate(`0,${length}`, `${length},${length}`);
});
svg.append("g")
.call(yAxis);
svg.append("g")
.call(xAxis);
return svg.node();
}
Insert cell
Insert cell
x = d3.scaleTime()
.domain(d3.extent(data, d => d.date))
.range([margin.left, width - margin.right])
Insert cell
y = d3.scaleLinear()
.domain([0, d3.max(data, d => d.close)])
.range([height - margin.bottom, margin.top])
Insert cell
d3.extent(data, d => d.close)
Insert cell
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.attr("class","y-axis")
.call(d3.axisLeft(y)
.tickValues([100, 200, 400, 300, 500, 600])
.tickSize(-width))
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.attr("class","x-axis")
.call(d3.axisBottom(x)
.tickFormat(formatDate)
.ticks(10))
Insert cell
Insert cell
line = d3.line()
.defined(d => d.close > 0)
.x(d => x(d.date))
.y(d => y(d.close))
Insert cell
line(data)
Insert cell
Insert cell
Insert cell
data_raw = d3.tsvParse(await FileAttachment("aapl.csv").text())
Insert cell
parseDate = d3.timeParse("%Y-%m-%d")
Insert cell
formatDate = d3.timeFormat("%b %y");
Insert cell
Insert cell
Insert cell
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