Skip to content

Instantly share code, notes, and snippets.

@tripp
Created June 10, 2011 16:22
Show Gist options
  • Save tripp/1019194 to your computer and use it in GitHub Desktop.
Save tripp/1019194 to your computer and use it in GitHub Desktop.
Add marker to chart based on time
function addDividendMarker(time)
{
var graph = mychart.get("graph"),
cb = graph.get("contentBox"),
axis = mychart.getAxisByKey("category"),
min = axis.get("minimum"),
max = axis.get("maximum"),
w = graph.get("width"),
h = graph.get("height"),
markerTime = time.valueOf(),
range = max - min,
x = Math.round(w * (markerTime - min)/range), //calculate x coordinate
y = Math.round(h * 0.7), //arbitrarily positioning y coordinate
marker = Y.config.doc.createElement('div'); //add content. You can include any images, text etc.
marker.setAttribute("style", "width:20px;height:20px;background-color:#f00;border:1px solid #000;position:absolute;");
//offset the marker by half its width and heigh
x -= parseFloat(Y.one(marker).getComputedStyle("width"))/2;
y -= parseFloat(Y.one(marker).getComputedStyle("height"))/2;
marker.style.left = x + "px";
marker.style.top = y + "px";
//add marker to the graph
cb.appendChild(marker);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment