Created
June 10, 2011 16:22
-
-
Save tripp/1019194 to your computer and use it in GitHub Desktop.
Add marker to chart based on time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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