How to add an image to an svg container using D3.js
nodeEnter.append(“svg:image”) .attr(‘x’, -9) .attr(‘y’, -12) .attr(‘width’, 20) .attr(‘height’, 24) .attr(“xlink:href”, “resources/images/check.png”)
nodeEnter.append(“svg:image”) .attr(‘x’, -9) .attr(‘y’, -12) .attr(‘width’, 20) .attr(‘height’, 24) .attr(“xlink:href”, “resources/images/check.png”)
Simply replace d3.json call with json = JSON.parse( myjson ); IE: var myjson = ‘{“name”: “flare”,”children”: [{“name”: “analytics”,”children”: [{“name”: “cluster”,”children”: [{“name”: “MergeEdge”, “size”: 10 }]}]}]}’; // d3.json(“/path/flare.json”, function(json) { #delete this line json = JSON.parse( myjson ); //add this line //rendering logic here //} #delete this line UPDATE 09/2013 Original code has changed. So varname … Read more
I ended up using the following code to break each x-axis label across lines: var insertLinebreaks = function (d) { var el = d3.select(this); var words = d.split(‘ ‘); el.text(”); for (var i = 0; i < words.length; i++) { var tspan = el.append(‘tspan’).text(words[i]); if (i > 0) tspan.attr(‘x’, 0).attr(‘dy’, ’15’); } }; svg.selectAll(‘g.x.axis g … Read more
not sure why, but there appears to be a discrepancy with the way jQuery and d3 handle events that causes a jQuery induced click event $(“#some-d3-element”).click() to not dispatch to the d3 element. a workaround: jQuery.fn.d3Click = function () { this.each(function (i, e) { var evt = new MouseEvent(“click”); e.dispatchEvent(evt); }); }; and then call … Read more
My approach is as under: Lets take the example you have illustrated in the attached figure: Jenny Of Oldstones is also a the child of Aegon V but the difference between this child and other children of Aegon V is that in this case I am not drawing the link between it. This is done … Read more
This tutorial can help you a lot to create a real time line graph: http://bost.ocks.org/mike/path/ I would like to add a few more comments: Asynchronous data When you do a real time graph, you often get the data asynchroneously, thus you cannot know the exact time between each “point”. For the line, you are lucky … Read more
You can use d3.select(this.parentNode) to select parent element of current element. And for selecting root element you can use d3.select(“#invisibleG”).
TL;DR With latest versions of D3, you can use selection.raise() as explained by tmpearce in its answer. Please scroll down and upvote! Original answer You will have to change the order of object and make the circle you mouseover being the last element added. As you can see here: https://gist.github.com/3922684 and as suggested by nautat, … Read more
From my investigations, d3.min is supposed to work on any kind of orderable values, not only numbers. isNaN would only work numbers. d3 was actually using == at some point. This commit introduced the x == x test: Unlike Math.min and Math.max, it doesn’t make sense to return negative or positive infinity for d3.min and … Read more
You can also get at the DOM element represented by a selection via selection.node() method var selection = d3.select(domElement); // later via the selection you can retrieve the element with .node() var elt = selection.node();