Guest User

Untitled

a guest
Oct 16th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Dot Plot</title>
  5. <script type="text/javascript" src="../../d3.v2.js"></script>
  6. <style type="text/css">
  7.  
  8. body {
  9. font: 10px sans-serif;
  10. }
  11.  
  12. path.dot {
  13. fill: white;
  14. stroke-width: 1.5px;
  15. }
  16.  
  17. rect {
  18. fill: none;
  19. stroke: black;
  20. shape-rendering: crispEdges;
  21. }
  22.  
  23. .x line, .y line {
  24. stroke: #ccc;
  25. shape-rendering: crispEdges;
  26. }
  27.  
  28. </style>
  29. </head>
  30. <body>
  31. <script type="text/javascript">
  32.  
  33. var data = d3.range(100).map(function(i) {
  34. return {x: i / 99, y: Math.random()};
  35. });
  36.  
  37. var width = 450,
  38. height = 450,
  39. margin = 20;
  40.  
  41. var x = d3.scale.linear()
  42. .range([0, width]);
  43.  
  44. var y = d3.scale.linear()
  45. .range([height, 0]);
  46.  
  47. var symbol = d3.scale.ordinal().range(d3.svg.symbolTypes),
  48. color = d3.scale.category10();
  49.  
  50. var vis = d3.select("body")
  51. .append("svg")
  52. .attr("width", width + margin * 2)
  53. .attr("height", height + margin * 2)
  54. .append("g")
  55. .attr("transform", "translate(" + margin + "," + margin + ")");
  56.  
  57. var xrule = vis.selectAll("g.x")
  58. .data(x.ticks(10))
  59. .enter().append("g")
  60. .attr("class", "x");
  61.  
  62. xrule.append("line")
  63. .attr("x1", x)
  64. .attr("x2", x)
  65. .attr("y1", 0)
  66. .attr("y2", height);
  67.  
  68. xrule.append("text")
  69. .attr("x", x)
  70. .attr("y", height + 3)
  71. .attr("dy", ".71em")
  72. .attr("text-anchor", "middle")
  73. .text(x.tickFormat(10));
  74.  
  75. var yrule = vis.selectAll("g.y")
  76. .data(y.ticks(10))
  77. .enter().append("g")
  78. .attr("class", "y");
  79.  
  80. yrule.append("line")
  81. .attr("x1", 0)
  82. .attr("x2", width)
  83. .attr("y1", y)
  84. .attr("y2", y);
  85.  
  86. yrule.append("text")
  87. .attr("x", -3)
  88. .attr("y", y)
  89. .attr("dy", ".35em")
  90. .attr("text-anchor", "end")
  91. .text(y.tickFormat(10));
  92.  
  93. vis.append("rect")
  94. .attr("width", width)
  95. .attr("height", height);
  96.  
  97. vis.selectAll("path.dot")
  98. .data(data)
  99. .enter().append("path")
  100. .attr("class", "dot")
  101. .attr("stroke", function(d, i) { return color(i); })
  102. .attr("transform", function(d) { return "translate(" + x(d.x) + "," + y(d.y) + ")"; })
  103. .attr("d", d3.svg.symbol()
  104. .type(function(d, i) { return symbol(i); }));
  105.  
  106. </script>
  107. </body>
  108. </html>
Add Comment
Please, Sign In to add comment