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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:28:25+00:00 2026-06-03T07:28:25+00:00

I’m just starting out with D3.js . I’ve created a simple enough donut chart

  • 0

I’m just starting out with D3.js. I’ve created a simple enough donut chart using this example. My problem is, if I have an array of objects as my data source – data points for ex. would be a1.foo or a1.bar – and I want to switch between them, how would i go about doing this? My current solution looks ugly and it can’t be the proper way of doing it – code below.

//Call on window change event
//Based on some parameter, change the data for the document
//vary d.foo to d.bar and so on

var donut = d3.layout.pie().value(function(d){ return d.foo})
arcs = arcs.data(donut(data)); // update the data

Is there a way I can set the value accessor at run time other than defining a new pie function?

  • 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-03T07:28:27+00:00Added an answer on June 3, 2026 at 7:28 am

    Generally to switch the data that is being displayed you would create a redraw() function that would then update the data for the chart. In the redraw you’ll need to make sure to handle the three cases – what should be done when data elements are modified, what should be done when new data elements are added, and what should be done when data elements are removed.

    It usually looks something like this (this example changes the data set through panning, but it doesn’t really matter). See the full code at http://bl.ocks.org/1962173.

    function redraw () {
    
        var rects, labels
          , minExtent = d3.time.day(brush.extent()[0])
          , maxExtent = d3.time.day(brush.extent()[1])
          , visItems = items.filter(function (d) { return d.start < maxExtent && d.end > minExtent});
    
        ...
    
        // upate the item rects
        rects = itemRects.selectAll('rect')
            .data(visItems, function (d) { return d.id; })   // update the data
            .attr('x', function(d) { return x1(d.start); })
            .attr('width', function(d) { return x1(d.end) - x1(d.start); });
    
        rects.enter().append('rect') // draw the new elements
            .attr('x', function(d) { return x1(d.start); })
            .attr('y', function(d) { return y1(d.lane) + .1 * y1(1) + 0.5; })
            .attr('width', function(d) { return x1(d.end) - x1(d.start); })
            .attr('height', function(d) { return .8 * y1(1); })
            .attr('class', function(d) { return 'mainItem ' + d.class; });
    
        rects.exit().remove(); // remove the old elements
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text

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.