D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
diegobarcena
Full window
Github gist
Practica D3
Built with
blockbuilder.org
<!DOCTYPE html> <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.csv("gapminder_data.csv", 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("cx", d => xScale(d.date)) .attr("cy", d => yScale(d.temperature)) .attr("radius",2) .attr("fill", "blue") .attr("stroke", "#FFF") /* svg.selectAll("rect") .data(datos) .enter().append("rect") .attr("x", d => xScale(d.date)) .attr("y", d => yScale(d.temperature)) .attr("width",2) .attr("height",d => heightScale(d.temperature)) .attr("fill", "blue") .attr("stroke", "#FFF") */ }) </script> </body>
https://d3js.org/d3.v5.min.js