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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:12:22+00:00 2026-06-02T05:12:22+00:00

I’m trying to change this pie chart, so that when I click on a

  • 0

I’m trying to change this pie chart, so that when I click on a segment, the color of the different segments don’t change. I see that the fill has a direct relationship with the shape of the segment, but I totally suck. Please help! You can see the pie chart in action here:

http://raphaeljs.com/growing-pie.html

function drawgrowingpie () {
    var r = Raphael("holder");

    r.customAttributes.segment = function (x, y, r, a1, a2) {
        var flag = (a2 - a1) > 180,
            clr = (a2 - a1) / 360;
        a1 = (a1 % 360) * Math.PI / 180;
        a2 = (a2 % 360) * Math.PI / 180;
        return {
            path: [["M", x, y], ["l", r * Math.cos(a1), r * Math.sin(a1)], ["A", r, r, 0, +flag, 1, x + r * Math.cos(a2), y + r * Math.sin(a2)], ["z"]],
            fill: "hsb(" + clr + ", .75, .8)"
        };
    };

    function animate(ms) {
        var start = 0,
            val;
        for (i = 0; i < ii; i++) {
            val = 360 / total * data[i];
            paths[i].animate({segment: [200, 200, 150, start, start += val]}, ms || 1500, "bounce");
            paths[i].angle = start - val / 2;
        }
    }

    var data = [24, 92, 24, 52, 78, 99, 82, 27],
        paths = r.set(),
        total,
        start,
        bg = r.circle(200, 200, 0).attr({stroke: "#fff", "stroke-width": 4});
    data = data.sort(function (a, b) { return b - a;});

    total = 0;
    for (var i = 0, ii = data.length; i < ii; i++) {
        total += data[i];
    }
    start = 0;
    for (i = 0; i < ii; i++) {
        var val = 360 / total * data[i];
        (function (i, val) {
            paths.push(r.path().attr({segment: [200, 200, 1, start, start + val], stroke: "#fff"}).click(function () {
                total += data[i];
                data[i] *= 2;
                animate();
            }));
        })(i, val);
        start += val;
    }
    bg.animate({r: 151}, 1000, "bounce");
    animate(1000);
};
  • 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-02T05:12:24+00:00Added an answer on June 2, 2026 at 5:12 am

    Change

    return {
        // snip...
        fill: "hsb(" + clr + ", .75, .8)"
    };
    

    to something else, or remove the fill property entirely from the returned object.


    Here’s a nudge in the right direction: instead of changing the color every time a slice is animated, the color is now passed to the segment function. This means that the two different callers (the initializer and the click handler) can control the color differently. The segment function is changed to not return any fill information if no clr (color) was passed to it. This means the color is unchanged by the click handler, since only the initialization code passes color information.

    Hopefully this makes sense to you.

    function drawgrowingpie() {
        var r = Raphael("holder");
                                                            // ↓↓↓ pass the color
        r.customAttributes.segment = function(x, y, r, a1, a2, clr) {
            var flag = (a2 - a1) > 180;
            a1 = (a1 % 360) * Math.PI / 180;
            a2 = (a2 % 360) * Math.PI / 180;
            var props = {
                path: [["M", x, y], ["l", r * Math.cos(a1), r * Math.sin(a1)], ["A", r, r, 0, +flag, 1, x + r * Math.cos(a2), y + r * Math.sin(a2)], ["z"]]
            };
    
            // only return fill properties if the color was passed
            if (clr) {
                props.fill = "hsb(" + clr + ", .75, .8)";
                console.log(clr);
            }
            return props;
        };
    
        function animate(ms) {
            var start = 0,
                val;
            for (i = 0; i < ii; i++) {
                val = 360 / total * data[i];
                paths[i].animate({
                    // notice that no color data is passed here...
                    segment: [200, 200, 150, start, start += val]
                }, ms || 1500, "bounce");
                paths[i].angle = start - val / 2;
            }
        }
    
        var data = [24, 92, 24, 52, 78, 99, 82, 27],
            paths = r.set(),
            total, start, bg = r.circle(200, 200, 0).attr({
                stroke: "#fff",
                "stroke-width": 4
            });
        data = data.sort(function(a, b) {
            return b - a;
        });
    
        total = 0;
        for (var i = 0, ii = data.length; i < ii; i++) {
            total += data[i];
        }
        start = 0;
        for (i = 0; i < ii; i++) {
            var val = 360 / total * data[i];
            (function(i, val) {
                paths.push(r.path().attr({
                    // ...but we do pass color data here      ↓↓↓↓  
                    segment: [200, 200, 1, start, start + val, val],
                    stroke: "#fff"
                }).click(function() {
                    total += data[i];
                    data[i] *= 2;
                    animate();
                }));
            })(i, val);
            start += val;
        }
        bg.animate({
            r: 151
        }, 1000, "bounce");
        animate(1000);
    }
    

    http://jsfiddle.net/mattball/xsfQj/

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.