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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:13:55+00:00 2026-06-07T22:13:55+00:00

I’ve managed to get the following working (pie chart changing dynamically based on a

  • 0

I’ve managed to get the following working (pie chart changing dynamically based on a slider value):

    var x = function() {
        return $("#slider").val();
    }

    var data = function() {
        return [x(), ((100-x())/2), ((100-x())/2)];
    }

    var w = 100,
        h = 100,
        r = 50,
        color = d3.scale.category20(),
        pie = d3.layout.pie().sort(null),
        arc = d3.svg.arc().outerRadius(r);

    var svg = d3.select("#chart").append("svg:svg")
        .attr("width", w)
        .attr("height", h)
      .append("svg:g")
        .attr("transform", "translate(" + w / 2 + "," + h / 2 + ")");

    var arcs = svg.selectAll("path")
        .data(pie(data()))
      .enter().append("svg:path")
        .attr("fill", function(d, i) { return color(i); })
        .attr("d", arc)
        .each(function(d) { this._current = d; });

    var redraw = function() {
      newdata = data(); // swap the data
      arcs = arcs.data(pie(newdata)); // recompute the angles and rebind the data
      arcs.transition().duration(750).attrTween("d", arcTween); // redraw the arcs
    };

    // Store the currently-displayed angles in this._current.
    // Then, interpolate from this._current to the new angles.
    function arcTween(a) {
      var i = d3.interpolate(this._current, a);
      this._current = i(0);
      return function(t) {
        return arc(i(t));
      };
    }

I can’t seem to modify it to include dynamic labels (use an object for data rather than an array {‘label’: ‘label1’, ‘value’: value}. How would I modify the above code to add labels?

  • 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-07T22:13:57+00:00Added an answer on June 7, 2026 at 10:13 pm

    This should work, keeping the labels and the pie chart as separate entities:

        var x = function() {
            return $("#slider").val();
        }
    
        var data = function() {
            return [x(), ((100-x())/2), ((100-x())/2)];
        }
    
        var labels = function() { 
            var label1 = "LABEL 1: " + x();
            var label2 = "LABEL 2: " + ((100-x())/2);
            var label3 = "LABEL 3: " + ((100-x())/2);
            return [label1, label2, label3];
        }
    
        var w = 200,
            h = 100,
            r = 50,
            color = d3.scale.category20(),
            pie = d3.layout.pie().sort(null),
            arc = d3.svg.arc().outerRadius(r);
    
        var svg = d3.select("#chart").append("svg:svg")
            .attr("width", w)
            .attr("height", h)
          .append("svg:g")
            .attr("transform", "translate(" + 50 + "," + h / 2 + ")");
    
        var arcs = svg.selectAll("path")
            .data(pie(data()))
            .enter().append("svg:path")
            .attr("fill", function(d, i) { return color(i); })
            .attr("d", arc)
            .each(function(d) { this._current = d; });
    
        var label_group = svg.selectAll("text")
            .data(labels())
            .enter()
            .append("text")
            .text(function(d) {
                return d;
            })
            .attr("x", 60)
            .attr("y", function(d, i) { return (i * 20) - 16; });
    
        var redraw = function() {
            newdata = data(); // swap the data
            arcs = arcs.data(pie(newdata)); // recompute the angles and rebind the data
            arcs.transition().duration(750).attrTween("d", arcTween); // redraw the arcs
            label_group = label_group.data(labels());
            label_group.transition().delay(300).text(function(d) {
                return d;
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.