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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:54:11+00:00 2026-06-07T14:54:11+00:00

I have a pie chart created with raphael. I have a form checkbox that

  • 0

I have a pie chart created with raphael. I have a form checkbox that when clicked I want to attach ‘effects’ to the pie. This example is trying to attach an inner glow with inGlowFun() by creating a circle after it with a gradient.

function allPie(){       

   var pie;     

        Raphael.fn.renderPie = function(cx,cy,r,values,total) {

            var canvas = this, 
                radian = Math.PI / 180,
                chart = this.set();

            function createSlice(cx, cy, r, startAngle, endAngle, params) {
                var x1 = cx + r * Math.cos(-startAngle * radian),
                    x2 = cx + r * Math.cos(-endAngle * radian),
                    y1 = cy + r * Math.sin(-startAngle * radian),
                    y2 = cy + r * Math.sin(-endAngle * radian);


                return canvas.path(["M", cx, cy, "L", x1, y1, "A", r, r, 0, +(endAngle - startAngle > 180), 0, x2, y2, "z"]).attr(params);
            }




            var angle = 90,
                process = function (j) {

                        var value = parseInt(values[j].spend, 10),
                        angleplus = 360 * value / total,
                        p = createSlice(cx, cy, r, angle - angleplus, angle, {fill: values[j].pieColour, stroke: "#FFF", "stroke-width": 1});

                    values[j].slice = p;    

                    angle -= angleplus;
                    chart.push(p);          
                };


            function glowFun(){
            canvas.circle(cx, cy, 140).attr({fill:"r#fff-#fff:96-#CCC", "stroke-width": 0});
            } 



            // creating each pie slice
            for (var i = 0, ii = values.length; i < ii; i++) {
                process(i);
            }
            //create inner gradient
            function hollowFun(){
            canvas.circle(cx, cy, 120).attr({fill:"85-#fff-#CCC", "stroke-width": 20, "stroke": "#FFF", 'opacity': 0.000001} );
            }




            // inner glow (I admit this is a bit of a hack but it keeps it simple)
            function inGlowFun(){
           canvas.circle(cx, cy, 55).attr({fill:"r#fff-#fff:85-#CCC", "stroke-width": 2, "stroke": "#FFF"});
            }
            if(box.checked){
            inGlowFun();
            }

            // returning the whole set of nodes for interactions later
            return chart;

        };







        // creating a namespace for this code so that anything we create won't effect other JavaScript on the page
        var dotNet = window.dotNet || {};








        /*
        a function that parses the data contained in the data table, creates the Raphaël object we're drawing too and calls our Raphaël plug-in
            $source - reference to the data source (an HTML table in this example)
            $container - reference to the HTML element we're creating the chart inside
        */    
        dotNet.makePie = function($source, $container, pie) {    
            var pie;
            /*
            few constannt variables for this function
                pieData - an empty array that will hold an object for each section
                totalSpend - the grand total of all the rows (calculated via code for greater accuracy)
            */
            var pieData = [],
                totalSpend = 0;


            /* 
            function to parse each table row, create HTML and attach events
                i - index of the iteraction
            */
            function prepare(i) {

                /*
                variables used for each call
                    row - jQuery object of the current table row
                    values - an empty object that will be filled with data and references associated with each row
                    head - jQuery object used to reference the th of the current row
                */
                var row = $(this),
                    values = {},
                    head = row.find('.tabh');

                // grabbing the numeric total for the row and assigning to values
                values.spend = row.find('.tdh').text();
                // each pie slice will now be styled in a CSS file -keeping style where it should be other than in JavaScript
                values.pieColour = row.find('th span').css('borderLeftColor');

                // increase total value
                totalSpend += parseInt(values.spend, 10);

                // push values into the array for access later
                pieData.push(values);

            }

            // iterate through each table row (only in the body)    
            $source.find('.tbh tr').each(prepare);



            // call the plugin to create the chart    
            var sizeman = 300
            var sizepiespace = sizeman /2
            var sizepie = sizeman / (30/13)
            if(pie){
            pie.clear();
            }
            pie = Raphael($container[0], sizeman, sizeman).renderPie(sizepiespace, sizepiespace, sizepie, pieData, totalSpend);

            // attaching an event to the Raphaël set that fades all the slice back to full opacity
            pie.mouseout(function() {
                pie.attr('opacity', 1);
            });

        };


// calling our makePie function on DOM ready
        function piefunc(){
         $(function() {
          dotNet.makePie($('table'),$('#pie'), pie);
    });
    }
   piefunc();

}

This is the checkbox that it applies to and where the pie is actually run.
            <form>
            <input type="checkbox" id="checker" onclick="checkFun();" />
            </form>

            <script type="text/javascript">



            var box = document.getElementById('checker');
        function checkFun(){
        allPie();

        }

    allPie();
    pieShower();
            </script>

When the checkbox is clicked it does generate a new pie with the desired effect, unfortunately it also pushes the previous version down and keeps it on the same page, and so as you keep checking and unchecking the box more and more are made on the page. Is there anyway to ‘delete’ or remove the chart that is already on the page while creating a new one with the desired effect?

  • 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-07T14:54:14+00:00Added an answer on June 7, 2026 at 2:54 pm

    try this

    make var pie a global variable instead local one

    and before the var pie = Raphael($container.....

    add the following

    if(pie){
        pie.clear();
    }
    

    also , your better use the graphael piechart api instead your current way (INMO)

    take a look at my jsfiddle with hover (glow like) effect + click callback

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

Sidebar

Related Questions

I have a pie chart created by graphael this.element = this.raphHolder.piechart(100, 100, 100, data,{legend
I have a report that contains a pie chart within it. I would want
I am trying to get a pie chart display correctly but have found there
I'm stuck trying to solve this. I'm plotting some information that I have in
I've created an ajax driven flot line chart that I would like to have
I want to have a JavaScript pie chart, I already have one with PlotKit,
I have a ControlTemplate that contains a XamWebChart . For each pie slice created
Hy, I have a chart,wich is created in runtime,this could be Line, Bar or
I have some code that generates image of a pie chart. It's a general
I am trying to display a pie chart that shows sales by company. However

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.