Built with blockbuilder.org
forked from DondeDijeDigo's block: Temperaturas Nueva York
xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v5.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
.barras div {
margin: 2px;
padding: 10px;
text-align: right;
color: white;
}
</style>
</head>
<body>
<h1>Barómetro Junio GAD3</h1>
<script>
const rectWidth = 41;
const width = 800
const height = 300
const city = "New York";
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height)
function typeClean(row){
r = {};
r.temperature = +row[city];//y
fecha = d3.timeParse("%Y%m%d")(row.date);
r.date = new Date(fecha);//x
return r;
}
d3.tsv("data.tsv",
row => typeClean(row)).then(datos =>
{
//Scales
const xExtent = d3.extent(datos, d => d.date)
const xScale = d3.scaleTime()
.domain(xExtent)
.range([0, width])
const yMax = d3.max(datos, d => d.temperature)
const yScale = d3.scaleLinear()
.domain([0, yMax])
.range([height, 0])
const heightScale = d3.scaleLinear()
.domain([0, yMax])
.range([0, height])
svg.selectAll("circle")
.data(datos)
.enter().append("circle")
.attr("x", d => xScale(d.date))
.attr("y", d => yScale(d.temperature))
.attr("radio", 50)
})
</script>
</body>
https://d3js.org/d3.v5.min.js