Public
Edited
Nov 1
1 star
Insert cell
md`# Running color lines (limited)
`
Insert cell
line = d3.line()
.x( (d,i) => x(i))
.y((d,i) => y(d))
.curve(d3.curveBasis);
Insert cell
chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);

svg
.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", width)
.attr("height", height - margin.bottom)
.attr("fill", "black");

draw();

function draw() {
var lines = 10;
var offset = height / (lines + 1);
for (var i = 0; i < lines; i++) {
var data = Array.from({ length: Math.random() * 72 + 28 }, () =>
Math.random()
);

var lineGroup = svg
.append("g")
.attr("transform", `translate(0,${-i * offset - offset / 4})`);

var randDuration = Math.random() * 4000 + 3000;

lineGroup
.append("path")
.datum(data)
.attr("class", `path${i}`)
.attr("stroke", color(i))
.attr("stroke-width", 6)
.style("mix-blend-mode", "screen")
.attr("d", line)
.transition()
.duration(randDuration)
.ease(d3.easeLinear)
.attrTween("stroke-dasharray", function (d, i) {
const length = this.getTotalLength();
return d3.interpolate(`0,${length}`, `${length},${length}`);
});
}
}

return svg.node();
}
Insert cell
lines = d3.range(10)
Insert cell
color = d3.scaleOrdinal(d3.schemeSet3)
Insert cell
data = Array.from({length: 100}, () => Math.random());
Insert cell
style = html`
<style>
line {
mix-blend-mode: screen;
}
<style>`
Insert cell
x = d3.scaleLinear()
.domain([0,100])
.rangeRound([-10, width-margin.right])
Insert cell
y = d3.scaleLinear()
.domain([0, 10])
.rangeRound([height - margin.bottom, margin.top])
.clamp(true)
Insert cell
height = 600
Insert cell
margin = ({ top: 0, right: 0, bottom: 0, left: 0 })
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