Advertisement
Guest User

Untitled

a guest
May 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.03 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <script src="http://d3js.org/d3.v3.min.js"></script>
  5.     <script src="http://d3js.org/topojson.v1.min.js"></script>
  6.   </head>
  7.   <body>
  8.     <script>
  9.       var width = 960;
  10.       var height = 500;
  11.       var projection = d3.geo.albers();
  12.       var path = d3.geo.path().projection(projection);
  13.       var svg = d3
  14.         .select("body")
  15.         .append("svg")
  16.         .attr("width", width)
  17.         .attr("height", height);
  18.        
  19.       d3.json("us.json", function(error, us) {
  20.         var statesData = topojson.feature(us, us.objects.states);
  21.         var states = svg
  22.           .selectAll("path.state")
  23.           .data(statesData.features)
  24.           .enter()
  25.           .append("path")
  26.           .classed("state", true)
  27.           .attr("d", path)
  28.           .style("fill", "blue")
  29.           .style("stroke", "white")
  30.           .style("stroke-width", 2)
  31.           .style("fill-opacity", function() {
  32.             return Math.random();
  33.           });
  34.       });
  35.     </script>
  36.   </body>
  37. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement