D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
35degrees
Full window
Github gist
profbeeswarm1
Built with
blockbuilder.org
<!DOCTYPE html> <meta charset="utf-8"> <style> .axis path, .axis line { fill: none; stroke: #000; shape-rendering: crispEdges; } .axis text { font: 10px sans-serif; } .cells path { fill: none; pointer-events: all; } .cells :hover circle { fill: Goldenrod; } </style> <svg width="960" height="200"></svg> <script src="https://d3js.org/d3.v4.min.js"></script> <script> var svg = d3.select("svg"), margin = {top: 40, right: 40, bottom: 40, left: 40}, width = svg.attr("width") - margin.left - margin.right, height = svg.attr("height") - margin.top - margin.bottom; var formatValue = d3.format(",d"); var x = d3.scaleLinear() .rangeRound([0, width]); var g = svg.append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); d3.csv("simple1.csv", type, function(error, data) { if (error) throw error; x.domain(d3.extent(data, function(d) { return d.Overall; })); var simulation = d3.forceSimulation(data) .force("x", d3.forceX(function(d) { return x(d.Overall); }).strength(1)) .force("y", d3.forceY(height / 2)) .force("collide", d3.forceCollide(4)) .stop(); for (var i = 0; i < 120; ++i) simulation.tick(); g.append("g") .attr("class", "axis axis--x") .attr("transform", "translate(0," + height + ")") .call(d3.axisBottom(x).ticks(20, ".0s")); var cell = g.append("g") .attr("class", "cells") .selectAll("g").data(d3.voronoi() .extent([[-margin.left, -margin.top], [width + margin.right, height + margin.top]]) .x(function(d) { return d.x; }) .y(function(d) { return d.y; }) .polygons(data)).enter().append("g"); cell.append("circle") .attr("r", 6) .attr("cx", function(d) { return d.data.x; }) .attr("cy", function(d) { return d.data.y; }) .attr("fill","IndianRed"); cell.append("path") .attr("d", function(d) { return "M" + d.join("L") + "Z"; }); cell.append("title") .text(function(d) { return d.data.Title + "\n" + formatValue(d.data.Overall); }); }); function type(d) { if (!d.Overall) return; d.Overall = +d.Overall; return d; } </script>
https://d3js.org/d3.v4.min.js