D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
romsson
Full window
Github gist
scatterplot in progress
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; } circle { fill: black; } </style> </head> <body> <script> var margin = {top: 20, right: 10, bottom: 20, left: 30}; var width = 960 - margin.left - margin.right, height = 500 - margin.top - margin.bottom; var svg = d3.select("body").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); var color = d3.scaleOrdinal(d3.schemeCategory20); var x = d3.scaleLinear() .range([0, width]); var y = d3.scaleLinear() .range([height, 0]); var r = d3.scaleSqrt() .range([2, 10]); var xAxis = d3.axisBottom() .scale(x); var yAxis = d3.axisLeft() .scale(y); xAxis(svg.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + height + ")")) svg.append('g') .attr('transform', 'translate(0,0)') .attr('class', 'y axis') .call(yAxis); d3.csv('iris.csv', function(error, data){ data.forEach(function(d){ d.sepal_length = +d.sepal_length; d.sepal_width = +d.sepal_width; d.petal_length = +d.petal_length; d.petal_width = +d.petal_width; }); x.domain(d3.extent(data, function(d) { return d.sepal_length; })); y.domain(d3.extent(data, function(d) { return d.sepal_width; })); r.domain(d3.extent(data, function(d) { return d.petal_length; })); svg.selectAll(".dot").data(data).enter() .append("circle") .attr("class", "dot") .attr("cx", function(d) { return x(d.sepal_length); }) .attr("cy", function(d) { return y(d.sepal_width); }) .attr("r", function(d) { return r(d.sepal_width); }) .style("fill", function(d) { return color(d.species); }); }); </script> </body>
https://d3js.org/d3.v4.min.js