D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
JohnDelacour
Full window
Github gist
Show/hide
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Click show hide</title> <script src="https://d3js.org/d3.v3.min.js"></script> <style type="text/css"> circle {fill: #000; stroke: #000;} </style> </head> <body> <script> var svg = d3.select("body").append("svg") .attr({width:600, height:600}) ; svg.append("rect") // "Hide" button .attr({x:0, width:60, height:40, fill:"red" }) .on("click", function() { // Hide all circles of class "dot" d3.selectAll(".dot").attr("visibility", "hidden") }) ; svg.append("rect") // "Show" button .attr({x:70, width:60, height:40, fill:"green" }) .on("click", function() { // Show all circles of class "dot" d3.selectAll(".dot").attr("visibility", "") }) ; var g0 = svg.append("g") // Group for dot grid .attr("transform", "translate(4 50)") ; var data = []; // Create coordinates for dots for(i = 0; i < 60; i++) { for (j = 0; j < 50; j++) { data.push( {cx:i*10, cy:j*10} ) ; } } g0.selectAll("circle") // Draw the dots .data(data) .enter().append("circle") .attr("class", "dot") .attr("r", 2) .attr("cx", function(d) {return d.cx}) .attr("cy", function(d) {return d.cy}) ; </script> </body> </html>
Modified
http://d3js.org/d3.v3.min.js
to a secure url
https://d3js.org/d3.v3.min.js