Created
August 16, 2013 10:27
-
-
Save cv711/6248809 to your computer and use it in GitHub Desktop.
Example of adding foreignObject tags in d3 chart, from a jsonp query.
(ATTENTION: foreignObject not supported by IE, switched to rickshaw library for that)
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
$.getJSON("<url>?callback=?",function(data){ | |
svg.selectAll(".names") | |
.data(data.entries.filter(function(d){ if(d.type == "SONG") return d;})) | |
.enter().append("foreignObject") | |
.attr("x",function(d){ return x(d.timestamp);}) | |
.attr("y", height) | |
.attr("width",300) | |
.attr("height",margin.between) | |
.append("xhtml:div") | |
.attr("class","songLabels") | |
.html(function(d){ | |
var temp = ""; | |
switch(d.type) | |
{ | |
case "SONG": | |
temp = "<p'>" +d.title+ "</p><p>" + d.artist + "</p>"; | |
break; | |
case "UNKNOWN": | |
temp = "<p> "+ d.type+"</p>"; | |
break; | |
default: | |
temp = "<p> "+ d.type+"</p>"; | |
break; | |
} | |
return temp; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment