How to show percentage in pie chart?

LilC
LilC New Altair Community Member
edited November 5 in Community Q&A
I have 2 different groups in the pie chart and the results are aggregated.
I want to show the percentage of each group's sales, instead of the sum of the sales.



Also, if I use Marco to calculate the percentage of each store, how can I display both the sales and the percentage in the result (not the chart)?

Can anyone help me with it?  

Best Answers

  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    edited July 2020 Answer ✓
    Hi,

    I'm afraid it's not obvious, but it is doable!


    You have to go to Plot style -> Labels style -> and enter "<b>{point.name}</b>: {point.percentage:.1f}%" as the Label value format.
    For the tooltip, you can add something like " => {point.percentage:.1f}%" as the tooltip Value suffix.

    Regards,
    Marco
  • LilC
    LilC New Altair Community Member
    edited July 2020 Answer ✓
    Hi, Marco, if it is for Sunburst chart, will it work as well?  
    Also, since some are less than 0.9% of the total, if there any way to display them as well?
  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    Answer ✓
    Hi,

    No, Sunburst does not support %. I suppose because it is usually very crowded with dozens of elements..
    Regarding your other question, the available space is determined by the library. I would assume it thinks there is not enough space and therefore does not show those anymore. You have too many small elements in the same space for the labels to be shown properly in a pie chart, if you ask me. Those would make the chart not very nice, even if they did fit on the screen.

    Regards,
    Marco

Answers

  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    edited July 2020 Answer ✓
    Hi,

    I'm afraid it's not obvious, but it is doable!


    You have to go to Plot style -> Labels style -> and enter "<b>{point.name}</b>: {point.percentage:.1f}%" as the Label value format.
    For the tooltip, you can add something like " => {point.percentage:.1f}%" as the tooltip Value suffix.

    Regards,
    Marco
  • LilC
    LilC New Altair Community Member
    edited July 2020 Answer ✓
    Hi, Marco, if it is for Sunburst chart, will it work as well?  
    Also, since some are less than 0.9% of the total, if there any way to display them as well?
  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    Answer ✓
    Hi,

    No, Sunburst does not support %. I suppose because it is usually very crowded with dozens of elements..
    Regarding your other question, the available space is determined by the library. I would assume it thinks there is not enough space and therefore does not show those anymore. You have too many small elements in the same space for the labels to be shown properly in a pie chart, if you ask me. Those would make the chart not very nice, even if they did fit on the screen.

    Regards,
    Marco
  • LilC
    LilC New Altair Community Member
    edited July 2020
    Thanks, Marco, you are awesome.
    Because I really need to show those top 10 stores' individual percentage.
    Is there a way to display them on the side of the bar chart?

    If not I'll just use macro to add a column.
  • Loan_Nguyen56
    Loan_Nguyen56 New Altair Community Member
    I want to show that in Rapid, please hep me. Thanks.

  • ksgenzer
    ksgenzer New Altair Community Member
    edited November 2023
    Hi @Marco_Boeck, is there a way to specify pie chart colors using hex codes? And can you specify the font (not just the size) for the labels?
  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    edited November 2023
    Hi @ksgenzer,

    Yes, you can specify the colors via hex code. You need to manually modify the configuration file, though. See the attached configuration for the Iris sample data set. It uses a simple red/green/blue color array in line #119 for the colors element of the styleConfiguration of the plotConfiguration.
    "colors" : ["#ff0000", "#00ff00", "#0000ff"],
    The font itself however cannot be specified unfortunately.

    Kind regards,
    Marco
  • ksgenzer
    ksgenzer New Altair Community Member
    That worked great--thank you @Marco_Boeck !