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 8557703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:38:04+00:00 2026-06-11T15:38:04+00:00

I am using array slice to page through data. When I get to the

  • 0

I am using array slice to page through data. When I get to the last page (which only has 7 elements instead of 10), I cannot remove the last 3 bars. .exit().remove() works on the other elements on the page, but will not work on the bars for some reason. How can I remove the bars 8-10 on the last page?

Here’s an example on jsfiddle:
http://jsfiddle.net/PMEaT/1/

Here’s the code from the jsfiddle:

var data = [1,1,1,1,1,1,1,1,6,7,3,3,3,3,3,3,3];
var chart = d3.select("body").append("svg")
.attr("class","chart")
.attr("width",440)
.attr("height",300);
var barnumber = 10;
var page = 1;

var y = d3.scale.linear()
.domain([0,10])
.range([0,300])

var viewdata = data.slice((page-1)*barnumber,page*barnumber);

var rect = chart.selectAll("rect")
.data(viewdata);

rect.enter().insert("rect")
    .attr("x",function(d,i){ return i*20})
    .attr("y",function(d) {return 300 - y(d);})
    .attr("width", 20)
    .attr("height", y);

chart.selectAll("text")
.data(viewdata)
    .enter().append("text")
    .attr("x", function(d,i) { return i*20+8; })
    .attr("y", 290)
    .text(String);

$('#next').click(function() {
    page++;
    viewdata = data.slice((page-1)*barnumber,page*barnumber);
    redraw();
});

$('#last').click(function() {
    page--;
    viewdata = data.slice((page-1)*barnumber,page*barnumber);
    redraw();
});

function redraw() {
rect.data(viewdata)
    .transition()
    .duration(500)
    .attr("x",function(d,i){ return i*20})
    .attr("y",function(d) {return 300 - y(d);})
    .attr("width", 20)
    .attr("height", y);

    chart.selectAll("text")
.data(viewdata)
     .transition()
    .duration(500)
    .text(String);

rect.exit().remove();

}
  • 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-11T15:38:05+00:00Added an answer on June 11, 2026 at 3:38 pm

    The data-operator doesn’t compute the data-join in-place; it returns a new selection. You’re not saving the result of selection.data, so your rect selection isn’t getting updated.

    Rather than chaining a transition directly off of the update selection of your data-join, you need to save the data-join first:

    // First save the result of the data-join.
    rect = rect.data(viewdata);
    
    // Then update.
    rect.transition()
        .duration(500)
        …
    
    // Then exit.
    rect.exit().remove();
    

    Of course, if you’re removing the exit selection, you’ll probably also need to append to the enter selection. Otherwise, when you get to that last page and try to go back, you’ll be stuck with only 7 bars forever rather than getting back to 10.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using an array of images with next/previous functions to navigate through the images.
I have an array which appears like the one below. I want to slice
I'm frequently using the following to get the second to last value in an
I need to filter an array to remove the elements that are lower than
I try to create a dynamic 2 dimensional array using the prototype.slice.call. The array
I know I can slice a string in Python by using array notation: str[1:6]
I am using Array() with each_with_index to output a array with index but I
I'm currently using Array.Copy to shift an array as such: Array.Copy(array, 0, array, 1,
I'm using Array.sample to return a random element from an array. I want to
I need to create an array of arrays. I have been using array_map(null,$a,$b,$c) to

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.