//defining the height and width of the svg container here
//will be assigning it to svg later
var width = 960,
height = 500,
// get this data from a http request using jquery AJAX
// or using some front-end http library
// since I use angularJS I usually rely on promises in JS
data = [{
name: "Twitter",
id: 245,
link: "twitter.com"
},{
name: "Google",
id: 243,
link: "google.com"
},{
name: "Github",
id: 344,
link: "github.com"
}];
// appending svg inside the container
var svg = d3.select("#chart").append("svg:svg")
.attr("width", width)
.attr("height", height)
.append("svg:g");
// Add a group for each cause.
var item = svg.selectAll("g")
.data(data)
.enter().append("g")
.attr("class", "item")
item.append("rect")
//change this logic below to place object on the svg canvas
.attr("x", function(d,i) { return i * 110; })
.attr("y", function(d,i) { return 1; })
.attr("height", 100)
.attr("width", 100)
.style("fill", 'black')
item.on('click', function(d){
//using jquery here to full content into the div
//there are better ways to do it, explore it online
$('#cover').show();
$('#popup_content').html("<li>"+d.name+" :"+d.id+"</li><li><a target='_blank' href='http://"+d.link+"/"+d.id+"'>click here</a></li>");
})
item.append("text")
.text(function(d){
return d.name+ " :"+d.id ;
})
.attr("x", function(d,i) { return (100*i) + (i*10); })
.attr("y", function(d,i) { return 100/2; })
.attr("fill",'#fff');
//jQuery for popup controls
//relace this with a library like light box to take care of you html popup
$('.close').click(function(){
$('#cover').hide();
})
$('#cover').click(function(){
$('#cover').hide();
})
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.