Public
Edited
May 12, 2024
Insert cell
Insert cell
data = FileAttachment("CNNactual_predict@1.csv").csv({typed: true})
Insert cell
width
Insert cell
height = 500
Insert cell
margins = ({
top: 50,
right: 30,
bottom: 30,
left: 40
})
Insert cell
// Declare the x (horizontal position) scale.
x = d3.scaleLinear(d3.extent(data, d => d.time), [margins.left, width - margins.right])
Insert cell
// Declare the y (vertical position) scale.
y = d3.scaleLinear()
.domain(d3.extent(data, d => d.actual)).nice()
.range([height - margins.bottom, margins.top])
Insert cell
lineActual = d3.line()
.x(d => x(d.time))
.y(d => y(d.actual))
Insert cell
linePrediction = d3.line()
.x(d => x(d.time))
.y(d => y(d.predict))
Insert cell
Insert cell
linechart = {

const svg = d3.create("svg")
.attr("width", width)
.attr("height", height)
.attr("viewBox", [0, 0, width, height])
.attr("style", "max-width: 100%; height: auto;");

svg.append("g")
.attr("transform", `translate(0,${height - margins.bottom})`)
.call(d3.axisBottom(x).ticks(width / 80))
.call(g => g.select(".domain").remove());

svg.append("g")
.attr("transform", `translate(${margins.left},0)`)
.call(d3.axisLeft(y).ticks(null, "+"))
.call(g => g.select(".domain").remove())
.call(g => g.selectAll(".tick line")
.clone()
.attr("x2", width - margins.right - margins.left)
.attr("stroke-opacity", d => d === 0 ? 1 : 0.1))
.call(g => g.append("text")
.attr("fill", "#000")
.attr("x", 5)
.attr("y", margins.top)
.attr("dy", "0.32em")
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text("Anomaly (°C)"))

// Append a path for the line.
svg.append("path")
.attr("fill", "none")
.attr("stroke", "blue")
.attr("stroke-width", 1)
.attr("d", lineActual(data))

// Append a path for the line.
svg.append("path")
.attr("fill", "none")
.attr("stroke", "#E4572E")
.attr("stroke-width", 2)
.attr("d", linePrediction(data))
return svg.node();
}
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more