Circular Arc – Doughnut Charts

Share

Facebook
Twitter
LinkedIn

A few weeks back Jhouz asked a question in the Chandoo.org ForumsIs is possible to create a doughnut chart like this one in excel?

This post will examine how to make it

Alert: It isn’t as straight forward as you may first think!

A couple of users responded with a Doughnut Chart

Which at first glance looks quite similar.

But the original author wanted round ends on the ends of the Doughnut segment. He also wanted a smooth chart.

A quick scan through the properties of a Doughnut Chart reveals there is no optionality to control the ends of the Doughnuts Segments. An alternative approach was required.

A Solution

Before starting, if you want to you can follow along using a sample file with the worked examples shown below: Download Here

The solution I posed was to use an X-Y Scatter chart for the line segments and apply a thick Line style.

The part of this approach that makes it work is that Line Styles have a property for the Lines End including an option for a round end.

The solution chart above consists of 2 lines

The first is the Background (Grey) line, which is a complete circle

The second line is the green line, which is a segment of the circle equal to in this case 45% of a circle or 162 Degrees (0.45 x 360). It is in front of the Grey line.

To apply this technique I used a number of Named Formula, and based the chart on these named formula:

First for the Background Grey chart segment

To define the Grey segment I applied 3 Named Formula:

c1_Rad =RADIANS(-(ROW(OFFSET(Sheet1!$A$1,,,360+1,1))-91))
_x1 =COS(c1_Rad)
_y1 =SIN(c1_Rad)

The Grey circle is defined by an Array of Radians of each degree between 0 and 360 of a circle.

C1_Rad                =RADIANS(-(ROW(OFFSET(Sheet1!$A$1,,,360+1,1))-91))

This works by using the Excel Row() and Offset() function to generate an array of Degrees from 0 to 360

The formula ROW(OFFSET(Sheet1!$A$1,,,360+1,1))

Will return ={1;2;3;4;5;6; …. ;358;359;360;361}

Note that we have taken the array 1 degree past 360 because the Row’s lowest value is Row 1, not row 0.

We then subtract 91 degrees from this to allow the Chart to start at the top of the circle.

The adjusted formula ROW(OFFSET(Sheet1!$A$1,,,360+1,1))-91

Returns: ={-90;-89;-88;-87; … ;268;269;270}

Finally the in front of the array changes the direction of the circle from Anticlockwise to clockwise.

Returns: ={90;89;88;87; … ;-268;-269;-270}

The Radians() function is used to convert the array of Degrees into an array of Radians

Returns: ={1.57;1.55;1.53; … ;-1.22;-1.23;-1.25}

The Radians above were rounded to 2 decimals places for display on this post, but Excel internally is using the full 15 decimal place precision.

We can now use this array of Radians to draw the background circle

To do this setup 2 new Named Formula

_x1: =COS(c1_Rad)

_y1: =SIN(c1_Rad)

Each of these will return an array of the X and Y values corresponding to each of the Radians from the previous c1_Rad array. The X and Y values will vary between -1 and 1. You may need these for Chart Scaling later.

If you want a circle of different radius simply multiply the x and y formulas like
_x1: =COS(c1_Rad)*5 for a radius of 5 and the same for the _y1 named formula

To plot these we add a X-Y Scatter Chart.

Select a single cell. Then goto the Insert, Chart, Scatter Chart menu and select a Scatter Chart with Smooth lines. This will give you a blank chart.

With the Chart Selected, Right click on the chart area and choose Select Data…

Add a Series using the Add button. Use the Worksheet Name Sheet1 and Named Formula _x1 & _y1 for the X and Y values

You can leave the Series Name blank or enter a value like “Background Circle”.
Note that you must enter the Sheet Name including the ! preceding the Named Formula name. Once you have accepted the inputs, if you return to the Edit Series dialog, notice that Excel now displays the Workbooks name instead of the Worksheets name. That’s quite ok.

You will now have a chart which looks like:

Finally Right click on the first series and select Format Data Series.

Set the Line Color to a Light Grey and set the Line Width to 12 . Check that Markers are set to None

Next the Foreground Green chart segment

To draw the front arc of the circle we add a few more Named Formula

_pct =Sheet1!$C$6
c2_Rad =RADIANS(-(ROW(OFFSET(Sheet1!$A$1,,,_pct*360+1,1))-91))
_x2 =COS(c2_Rad)
_y2 =SIN(c2_Rad)

_pct stores the value of the percentage of the circle directly from the reference cell on the worksheet eg: 45%

To draw an arc we only need to factor the 360 Degrees for a full circle back to the percentage required for the arc: ie: from 0 to 45% x 360 degrees = 162 Degrees. Hence drawing an Arc from 0 degrees to 162 Degrees.

To do this we use the same formula as before except that we set the range to the 45% of 360 degrees using the Named Formula:

C2_Rad: =RADIANS(-(ROW(OFFSET(Sheet1!$A$1,,,_pct*360+1,1))-91))

Add another series to the chart using.

With the Chart Selected, Right click on the chart area and choose Select Data…

X values: =Sheet1!_x2

Y values: =Sheet1!_y2

Next select the chart and ensure that the 45% circle is in front of the full circle

Select the Chart’s 2nd series and change the line width and line color to suit the impact you want.

Finally select the 45% line

Goto the Lines properties and set the Cap type to Round

Add the Measurement

With the Chart selected, goto the Insert, Text Box dialog and select a text box style and insert it.

With the text box selected, goto the Formula Bar and enter the Formula =_pct and press Enter or click the Tick icon to accept.

Finally with the text box selected, Change the Font Size to suit eg: 64 and Format the Text using an appropriate style from the Drawing Tools, Format Menu

Ensure the Text box is wide enough to display up to 100% include the percentage sign

The Final Chart

and with another value…

Other line type endings

Experiment with other Line Ends and see what you can make?

and Line Styles and Thicknesses?

Multiple Series

By careful use of  chart series you can add multiple measurements to the same chart and use a combination of display properties to enhance your chart

Conclusion

In conclusion I have demonstrated a successful solution to Jhouz’s original post and then extended it a bit further.

The Author acknowledges that there is limited use for doughnut charts and only recommends them in limited circumstances.

I hope these enhancements allow you to better use and emphasise your data in your situation as well as add another Excel technique to your arsenal.

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

13 Responses to “Using pivot tables to find out non performing customers”

  1. David Onder says:

    To avoid the helper column and the macro, I would transpose the data into the format shown above (Name, Year, Sales).  Now I can show more than one year, I can summarize - I can do many more things with it.  ASAP Utilities (http://www.asap-utilities.com) has a new experimental feature that can easily transpose the table into the correct format.  Much easier in my opinion.

    David 

    • Chandoo says:

      Of course with alternative data structure, we can easily setup a slicer based solution so that everything works like clockwork with even less work.

  2. Martin says:

    David, I was just about to post the same!
    In Contextures site, I remember there's a post on how to do that. Clearly, the way data is layed out on the very beginning is critical to get the best results, and even you may thinkg the original layout is the best way, it is clearly not. And that kind of mistakes are the ones I love ! because it teaches and trains you to avoid them, and how to think on the data structure the next time.
     
    Eventually, you get to that place when you "see" the structure on the moment the client tells you the request, and then, you realized you had an ephiphany, that glorious moment when data is no longer a mistery to you!!!
     
    Rgds,

  3. JMarc says:

    Chandoo,
    If the goal is to see the list of customers who have not business from yearX, I would change the helper column formula to :  =IF(selYear="all",sum(C4:M4),sum(offset(C4:M4,,selyear-2002,1,columns(C4:M4)-selyear+2002)))
     This formula will sum the sales from Selected Year to 2012.

    JMarc

  4. Elias says:

    If you are already using a helper column and the combox box runs a macro after it changes, why not just adjust the macro and filter the source data?
     
    Regards

  5. RichW says:

    I gotta say, it seems like you are giving 10 answers to 10 questions when your client REALLY wants to know is: "What is the last year "this" customer row had a non-zero Sales QTY?... You're missing the forest for the trees...
    Change the helper column to:
    =IFERROR(INDEX(tblSales[[#Headers],[Customer name]:[Sales 2012]],0,MATCH(9.99999999999999E+307,tblSales[[#This Row],[Customer name]:[Sales 2012]],1)),"NO SALES")
    And yes, since I'm matching off of them for value, I would change the headers to straight "2002" instead of "Sales 2002" but you sort the table on the helper column and then and there you can answer all of your questions.

  6. Kevin says:

    Hi thanks for this. Just can't figure out how you get the combo box to control the pivot table. Can you please advise?
     
    Cheers

  7. Kevin says:

    Thanks Chandoo. But I know how to insert a combobox, I was more referring to how does in control the year in the pivot table? Or is this obvious?  I note that if I select the Selected Year from the PivotTable Field List it says "the field has no itens" whereas this would normally allow you to change the year??
     
    Thanks again

  8. Kevin says:

     
    worked it out thanks...
    when =data!Q2 changes it changes the value in column N:N and then when you do a refreshall the pivottable vlaues get updated 
     
    Still not sure why PivotTable Field List says “the field has no itens"?? I created my own pivot table and could not repeat that.

  9. Bermir says:

    Hi, I put the sales data in range(F5:P19) and added a column D with the title 'Last sales in year'. After that, in column D for each customer, the simple formula

    =2000+MATCH(1000000,E5:P5)

    will provide the last year in which that particular customer had any sales, which can than easily be managed by autofilter.

    • Bermir says:

      Somewhat longer but perhaps a bit more solid (with the column titles in row 4):

      =RIGHT(INDEX($F$4:$P$19,1,MATCH(1000000,F5:P5)),4)

Leave a Reply