D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
romsson
Full window
Github gist
iris scatteplot simple
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 data = d3.range(100).map(function(d) { return {"x": Math.random(), "y": Math.random()} }) var x = d3.scaleLinear() //.domain([0, d3.max(data, function(d) { return d.x; })]) .range([200, 600]); var y = d3.scaleLinear() //.domain([0, d3.max(data, function(d) { return d.y; })]) .range([100, 400]); var color = d3.scaleOrdinal(d3.schemeCategory20); d3.text('iris.csv', function(error, raw){ var dsv = d3.dsvFormat(',') var data = dsv.parse(raw); 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; })) svg.selectAll("circle").data(data).enter() .append("circle") .style("fill", function(d, i) { return color(d.species); }) .style("stroke", "black") .attr("r", 10) .attr("cx", function(d) { return x(d.sepal_length); }) .attr("cy", function(d) { return y(d.sepal_width); }) }) </script> </body>
https://d3js.org/d3.v4.min.js