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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:20:44+00:00 2026-05-26T15:20:44+00:00

I’m trying to use a raphael.js example located here: http://raphaeljs.com/pie.html but I want to

  • 0

I’m trying to use a raphael.js example located here:

http://raphaeljs.com/pie.html

but I want to convert the pie graph into a donut graph (have a hole in the middle of all the slices). Currently, each slice is being created with the following code:

function sector(cx, cy, r, startAngle, endAngle, params) {
        //console.log(params.fill);
        var x1 = cx + r * Math.cos(-startAngle * rad),
            x2 = cx + r * Math.cos(-endAngle * rad),
            y1 = cy + r * Math.sin(-startAngle * rad),
            y2 = cy + r * Math.sin(-endAngle * rad);
        return paper.path(["M", cx, cy, "L", x1, y1, "A", r, r, 0, +(endAngle - startAngle > 180), 0, x2, y2, "z"]).attr(params);
    }

How would I modify this so that a hole of a fixed radius was removed from the overall pie? I saw this post here, which helps, but I can’t quite tell how or where to apply it to my code above:

How to achieve 'donut holes' with paths in Raphael

  • 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-05-26T15:20:45+00:00Added an answer on May 26, 2026 at 3:20 pm

    The way how one slice of the pie is created is like this:

    1. move to the center of the circle (cx,cy): “M”, cx, cy
    2. draw a line until the edge, where the arc will start (x1,y1): “L”, x1, y1
    3. draw an arc based on some mathematical calculations: “A”, r, r, 0, +(endAngle – startAngle > 180), 0, x2, y2
    4. draw a line back to the middle of the circle: in this case “z” is used; it means move to origin(cx,cy)

    and the slice(path) is ready.

    In order to create the donut you need to modify how the path is composed. You need to have a path composed of 2 arcs(inside and outside) and 2 lines to complete it.

    So first you need to find the starting point for the path, based on the radius of the imaginary empty circle that will be in the middle of the donut (with the radius rin). Lets call the coordinates of this point xx1 and yy1:

    xx1 = cx + rin * Math.cos(-startAngle * rad)
    yy1 = cy + rin * Math.sin(-startAngle * rad)
    

    You start building the path from this point( “M”, xx1, yy1 );
    http://jsfiddle.net/EuMQ5/425/

    Next step is to draw the line to the edge of the circle( “L”, x1, y1 ). From there you will have to draw the outer arc( “A”, r, r, 0, +(endAngle – startAngle > 180), 0, x2, y2 ) then one more line to the other edge of the inner arc( “L”, xx2, yy2 ). To get the values for xx2 and yy2:

    xx2 = cx + rin * Math.cos(-endAngle * rad)
    yy2 = cy + rin * Math.sin(-endAngle * rad)  
    

    and the last step is to complete the path by drawing the inner arc( “A”, rin, rin, 0, +(endAngle – startAngle > 180), 1, xx1, yy1 ). And now you have a piece of a donut.

    The fiddle is here.

    **updated fiddle link

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
i got an object with contents of html markup in it, for example: string
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has

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.