Advertisement
Guest User

Untitled

a guest
May 26th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>1860_homeground_stats</title>
  6. <script type="text/javascript" src="../d3.v3.js"></script>
  7. <style type="text/css">
  8.  
  9. body {
  10. background-color: #ddddff;
  11. }
  12.  
  13. svg {
  14. background-color: white;
  15. }
  16.  
  17. </style>
  18. </head>
  19. <body>
  20.  
  21. <script type="text/javascript">
  22.  
  23.  
  24. var svg = d3.select("body")
  25. .append("svg")
  26. .attr("width", 300)
  27. .attr("height", 400);
  28.  
  29.  
  30.  
  31. d3.csv("stadium_scores_clear.csv", function(data) {
  32.  
  33. data.sort(function(a, b) {
  34. return d3.descending(a.percentage_of_wins, b.percentage_of_wins);
  35.  
  36. //If your numeric values aren't sorting properly,
  37. //try commenting out the line above, and instead using:
  38. //
  39. //return d3.descending(+a.lifeSatisfaction, +b.lifeSatisfaction);
  40. //
  41. //Data coming in from the CSV is saved as strings (text),
  42. //so the + signs here force JavaScript to treat those
  43. //strings instead as numeric values, thereby fixing the
  44. //sort order (hopefully!).
  45. });
  46.  
  47. var rects = svg.selectAll("rect")
  48. .data(data)
  49. .enter()
  50. .append("rect");
  51.  
  52. rects.attr("x", 0)
  53. .attr("y", function(d, i) {
  54. return i * 10;
  55. })
  56. .attr("width", function(d) {
  57. return d.percentage_of_wins;
  58. })
  59. .attr("height", 8);
  60.  
  61. });
  62.  
  63.  
  64. </script>
  65.  
  66. </body>
  67. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement