Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8502069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:23:01+00:00 2026-06-11T01:23:01+00:00

I want to make a graph that structures different information, a bit like pearltrees

  • 0

I want to make a graph that structures different information, a bit like “pearltrees” (http://www.pearltrees.com/).
At the moment I have elements being shown (but not yet associated with any kind of data) an I have links between them (every element is attached to the one before).
The problem is: the connections are there but nor visible.
Hint: it’s not the browser, must be the code 😉
Tried a lot, searched on the internet, but now I think this problem costs me to much time, so I want to ask You.

<!DOCTYPE html>
<html>
<head>
     <script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?1.25.0">       
     </script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.geom.js?1.25.0"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js?1.25.0"></script>
 <style type="text/css">
link { stroke: #999; }
</style>
</head>
<body>
<div></div>

<script type="text/javascript">

 var w = 960,
h = 650,
nodes = [],
node,
 i = 0,
 links = [];

var vis = d3.select("body").append("svg:svg")
.attr("width", w)
.attr("height", h);


//create force:
var force = d3.layout.force()           
.nodes(nodes)                           
.links(links)                               
.linkDistance(30)
.charge([-50])                      
.friction([0.98])   
.gravity([0.025])                       
.size([w, h]);

 //apply the force
force.on("tick", function(e) {      
    vis.selectAll("path")
    .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });   
});

//add 15 objects that are connected each to the one before.
setInterval(function(){
if(i<15){ 
    nodes.push({
        size: Math.random() * 300 + 100,
        id: i
    });
    if(i!=0){
        links.push({source: nodes[i], target: nodes[i-1]});
    }
}

i = i+1;    

vis.selectAll("path")
  .data(nodes)
  .enter().append("svg:path")
  .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
  .attr("d", d3.svg.symbol()
  .size(function(d) { return d.size; })
  .type(function(d) { return d.type; }))
  .style("fill", "steelblue")
  .style("stroke", "white")
  .style("fill-opacity", "0.9")
  .style("stroke-width", "1.5px")
  .call(force.drag);


// Restart the force layout.
force
  .nodes(nodes)
  .links(links)
  .start();

drawLines(); 

//enter new nodes:
node.enter().append("svg:circle")
  .attr("class", "node")
  .attr("cx", function(d) { return d.x; })
  .attr("cy", function(d) { return d.y; })
  .attr("r", function(d) { return Math.sqrt(d.size) / 10 || 4.5; })
  .style("fill", color)
  .on("click", click)
  .call(force.drag);

// Exit old nodes:
node.exit().remove();
}, 1000);

function drawLines(){
lines = svg.selectAll("line.link")
    .data(links);
lines.enter().insert("svg:line", "circle.node")
    .attr("class", "link")
    .attr("x1", function(d) { return d.source.x; })
    .attr("y1", function(d) { return d.source.y; })
    .attr("x2", function(d) { return d.target.x; })
    .attr("y2", function(d) { return d.target.y; })
    .attr("drawn", 1)
    .style("stroke", "black")
    .style("stroke-width", 1)
    .style("fill", "black");
d3.selectAll("link").style("color", "black");
}

This is still a set of example-code from the D3.js-examples-site, but this will be changed in further developement.

Thanks for helping.

edit: posted more code to show you how the whole script works/does not work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:23:03+00:00Added an answer on June 11, 2026 at 1:23 am

    I’m not exactly sure what made it, but now it’s working.

    Stored the nodes as well as links in one variable, because JSON refused to work, ans now it does the links as it is supposed to.

    force
      .nodes(jsonData.nodes)
      .links(jsonData.links)
      .start();
    
    var link = svg.selectAll(".link")
      .data(jsonData.links)
    .enter().append("line")
      .attr("class", "link");
    
    var node = svg.selectAll(".node")
      .data(jsonData.nodes)
    .enter().append("g")
      .attr("class", "node")
      .call(force.drag);
    
    node.append("image")
      .attr("xlink:href", "../img/perry_rhodan.png")
      .attr("x", -8)
      .attr("y", -8)
      .attr("width", 30)
      .attr("height", 30);
    
    node.append("text")
      .attr("dx", 12)
      .attr("dy", ".35em")
      .attr("fill", "#aa0000")
      .text(function(d) { return d.name });
    
    node.append("title")
        .text(function(d) { return d.skill; });    
    
    force.on("tick", function() {
    link.attr("x1", function(d) { return d.source.x; })
        .attr("y1", function(d) { return d.source.y; })
        .attr("x2", function(d) { return d.target.x; })
        .attr("y2", function(d) { return d.target.y; });
    
      node.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make interactive graph like this using Qt and C++ : http://jsxgraph.uni-bayreuth.de/wiki/index.php/Cubic_spline_interpolation
I have a test graph here that I would like to tweak to make
I have to make a 3D graph in Excel. On the x-axis I want
I want to draw a graph that will be something like this: alt text
I have an application which utilizes graph (tree-like) custom structures. The structures are not
I want to make an iOS app that allows me to graph the intonation
I want to make an app which shows cardio graph in real time. That
I want to make a smooth and nice graph with no legend as it
I want to be able to make a line graph using GTK+ but I'm
I have style sheet with a class name changebackgroundcolor i want make change in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.