column.html 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <html>
  2. <head>
  3. <title>Column Chart</title>
  4. <script type="text/javascript" src="../protovis-d3.1.js"></script>
  5. </head>
  6. <body>
  7. <script type="text/javascript+protovis">
  8. var data = pv.range(10).map(Math.random),
  9. w = 250,
  10. h = 400,
  11. x = pv.Scale.ordinal(pv.range(10)).splitBanded(0, w, 4/5),
  12. y = pv.Scale.linear(0, 1).range(0, h);
  13. var vis = new pv.Panel()
  14. .width(w)
  15. .height(h)
  16. .bottom(20)
  17. .left(20)
  18. .right(5)
  19. .top(5);
  20. var bar = vis.add(pv.Bar)
  21. .data(data)
  22. .left(function() x(this.index))
  23. .width(x.range().band)
  24. .bottom(0)
  25. .height(y);
  26. bar.anchor("top").add(pv.Label)
  27. .textStyle("white")
  28. .text(function(d) d.toFixed(1));
  29. bar.anchor("bottom").add(pv.Label)
  30. .textMargin(5)
  31. .textBaseline("top")
  32. .text(function() "ABCDEFGHIJK".charAt(this.index));
  33. vis.add(pv.Rule)
  34. .data(y.ticks())
  35. .bottom(function(d) Math.round(y(d)) - .5)
  36. .strokeStyle(function(d) d ? "rgba(255,255,255,.3)" : "#000")
  37. .add(pv.Rule)
  38. .left(0)
  39. .width(5)
  40. .strokeStyle("#000")
  41. .anchor("left").add(pv.Label)
  42. .text(function(d) d.toFixed(1));
  43. vis.render();
  44. </script>
  45. </body>
  46. </html>