Advertisement
kberg

Candidate polls with prototype dygraphs drawing callback API

Jan 22nd, 2012
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var srcs = [ "romney.png", "gingrich.png", "paul.png", "santorum.png", "perry.png"];
  2. var images = [];
  3. var loadCount = 0;
  4. for (var i = 0; i < srcs.length; i++) {
  5.   images[i] = new Image();
  6.   images[i].addEventListener('load', function () {
  7.     loadCount++;
  8.     if (loadCount == srcs.length) {
  9.       drawGraph();
  10.     }
  11.   }, false);
  12.   images[i].src = srcs[i];
  13. }
  14. function drawGraph() {
  15.   var xyz = {
  16.     "Romney": images[0],
  17.     "Gingrich": images[1],
  18.     "Paul": images[2],
  19.     "Santorum" : images[3],
  20.     "Perry" : images[4]
  21.   };
  22.   g = new Dygraph(
  23.         document.getElementById("demodiv"), data,
  24.         {
  25.           labels: ["Date","Romney","Gingrich","Paul","Santorum","Perry"],
  26.           pointSize: 1,
  27.           drawPoints: true,
  28.           connectSeparatedPoints: true,
  29.           drawPointCallback: function(g, series, ctx, cx, cy, color, radius) {
  30.             var img = xyz[series];
  31.             console.log(series, cx, cy);
  32.           },
  33.           width:2400,
  34.           height: 800,
  35.         }
  36.   );
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement