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

  • SEARCH
  • Home
  • 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 7629667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:53:37+00:00 2026-05-31T05:53:37+00:00

I have a treemap I put together with d3.js. I populate the data via

  • 0

I have a treemap I put together with d3.js. I populate the data via getJSON. It works great. However, I have this functionality in a setInterval method and it doesnt seem to be refreshing itself.

    var treemap = d3.layout.treemap()
.padding(4)
.size([w, h])
.value(function(d) { return d.size; });

var svg = d3.select("#chart").append("svg")
.style("position", "relative")
.style("width", w + "px")
.style("height", h + "px");



function redraw3(json) {
  var cell = svg.data([json]).selectAll("g")
      .data(treemap)
    .enter().append("g")
      .attr("class", "cell")
      .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });

  cell.append("rect")
      .attr("width", function(d) { return d.dx; })
      .attr("height", function(d) { return d.dy; })
      .style("fill", function(d) { return d.children ? color(d.data.name) : null; });

  cell.append("text")
      .attr("x", function(d) { return d.dx / 2; })
      .attr("y", function(d) { return d.dy / 2; })
      .attr("dy", ".35em")
      .attr("text-anchor", "middle")
      .text(function(d) { return d.children ? null : d.data.name; });

}



setInterval(function() {
d3.json("http://localhost:8080/dev_tests/d3/examples/data/flare2.json", function(json) {
redraw3(json);
});
}, 3000);

My question specifically, is why when I change data in the json file doesn’t it show up 3 seconds later in the treemap?

Thank you in advance.

  • 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-05-31T05:53:38+00:00Added an answer on May 31, 2026 at 5:53 am

    What’s in the data? Because if the data array has the same length, the enter() selection (which corresponds to previously unbound data) will have a length of zero. Mike Bostock wrote a great tutorial called Thinking with Joins, which I would recommend reading before you go any further.

    The svg.data() call seems redundant, and for clarity’s sake I’d recommend doing this instead:

    var leaves = treemap(json);
    console.log("leaves:", leaves); // so you can see what's happening
    
    // cell here is the bound selection, which has 3 parts
    var cell = svg.selectAll("g")
      .data(leaves);
    // you might want to console.log(cell) here too so you can take a look
    
    // 1. the entering selection is new stuff
    var entering = cell.enter()
      .append("g")
    entering.append("rect")
      // [update rectangles]
    entering.append("text")
      // [update text]
    
    // 2. the exiting selection is old stuff
    cell.exit().remove();
    
    // 3. everything else is the "updating" selection
    cell.select("rect")
      // [update rectangles]
    cell.select("text")
      // [update text]
    

    You can also encapsulate the updating of cells in a function and “call” it on both the entering and updating selections, so you don’t have to write the same code twice:

    function update() {
      cell.select("rect")
        // [update rectangles]
      cell.select("text")
        // [update text]
    }
    
    entering.append("rect");
    entering.append("text");
    entering.call(update);
    
    cell.call(update);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have following map: NavigableMap<Integer,String> nmap = new TreeMap<Integer,String>(); nmap.put(3, Three); nmap.put(1, One);
Ok I have this code: TreeMap<DateTime, Integer> tree2 = getDatesTreeMap(); DateTime startx = new
I have this application that requires the creation of TreeMap<>() and this map only
I have a method that gets a SortedMap as input, this map holds many
I have these two data structures: public TreeMap<String, Integer> tableFrequency; public SortedSet<Map.Entry<String, Integer>> sortedTable;
My app uses a TreeMap to keep data sorted and have log(n) lookups &
I have a TreeMap, that looks like this: TreeMap<Instant, HashMap<Type, Double>> The Instant values
I have a treemap containing occurrence of words like this ... TreeMap <String,Integer> occurrence
I have written a google visualization treemap wrapper for GWT. I can successfully draw
I've tried this a couple ways, the first is have a class that implements

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.