Published
Edited
Nov 24, 2020
1 star
Insert cell
Insert cell
chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

const gradient = DOM.uid();

svg.append("g")
.call(xAxis);

svg.append("g")
.call(yAxis);

svg.append("linearGradient")
.attr("id", gradient.id)
.attr("gradientUnits", "userSpaceOnUse")
.attr("x1", 0)
.attr("y1", height - margin.bottom)
.attr("x2", 0)
.attr("y2", margin.top)
.selectAll("stop")
.data(d3.ticks(0, 1, 10))
.join("stop")
.attr("offset", d => d)
.attr("stop-color", color.interpolator());

svg.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", gradient)
.attr("stroke-width", 3)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("d", line);

return svg.node();
}
Insert cell
height = 150
Insert cell
margin = ({top: 20, right: 30, bottom: 30, left: 40})
Insert cell
data.map(d => d.date)
Insert cell
x = d3.scaleUtc()
.domain(d3.extent(data, d => d.date))
.range([margin.left, width - margin.right])
Insert cell
y = d3.scaleLinear()
.domain(d3.extent(data, d => d.value)).nice()
.range([height - margin.bottom, margin.top])
Insert cell
color = d3.scaleSequential(y.domain(), d3.interpolateOranges)
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0))
.call(g => g.select(".domain").remove())
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.call(g => g.select(".domain").remove())
.call(g => g.select(".tick:last-of-type text").append("tspan").text(data.y))
Insert cell
line = d3.line()
.curve(d3.curveMonotoneX) // <-- Com ou seu suavização?
// .curve(d3.curveCardinal.tension(0.4))
.defined(d => !isNaN(d.value))
.x(d => x(d.date))
.y(d => y(d.value))
Insert cell
Insert cell
dataOld = Object.assign(d3.csvParse(await FileAttachment("temperature.csv").text(), d3.autoType).map(({date, temperature}) => ({date, value: temperature})), {title: "Temperature °F", y: " °F"})
Insert cell
dataLeggo = d3.json("https://api.leggo.org.br/pressao/7c4cbac341769f758f433b3f2e0c08c9?interesse=leggo", d3.autoType)
Insert cell
data = dataLeggo.map(d => {d.value = d.trends_max_pressao_principal; d.date = new Date(d.date); return d})
Insert cell
d3 = require("d3@6")
Insert cell
import {legend} from "@d3/color-legend"
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