D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
salesdj
Full window
Github gist
kekekekke
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <script> // Feel free to change or delete any of the code you see in this editor! var svg = d3.select("body").append("svg") .attr("width", 960) .attr("height", 500) var sum, max, min, svgContainer = d3.select("svg") .attr("width", 1300) .attr("height", 10500) .style("background", "white"); var data = d3.data; d3.json(function (d) { sum += +d.consumption_gj_; }); var max = d3.max(data, function (d) { return +d.consumption_gj_; }); var min = d3.min(data, function (d) { return +d.consumption_gj_; }); //here I am declaring the domain and range by passing the max, min as paramters var rScale = d3.scale.linear() .domain([min, max]) .range([10, 150]); data.forEach(function(d,i){ d.radius = rScale(d.consumption_gj_); if (i !== 0){ d.ypos = d.radius*2 + data[i-1].ypos; } else { d.ypos = d.radius*2; } }) var circles = svgContainer.selectAll("circle") .data(data) .enter() .append("circle"); var circleAttributes = circles.attr("cx", '150') .attr("cy", function (d,i) { console.log(dy); return d.ypos + 5*i; //this is a very gray area }) .attr("r", function(d) { return d.radius;}) //passing the scale variable as a parameter to the radius .style("fill", "red") .style('stroke', 'black') .attr("index", function(d, i) { return i; }); </script> </body>
https://d3js.org/d3.v4.min.js