Skip to content

Pie

Overview

The pie trace type is used to create pie charts, which are circular charts divided into sectors representing proportions of a whole. Each sector’s arc length is proportional to the quantity it represents. Pie charts are great for visualizing part-to-whole relationships.

You can customize the colors, labels, and hover information to display your data effectively.

Common Uses

  • Part-to-Whole Relationships: Visualizing how different parts contribute to the whole.
  • Categorical Data: Showing the proportions of different categories in a dataset.
  • Survey Data: Visualizing how responses are distributed among categories.

Check out the Attributes for the full set of configuration options

Examples

Common Configurations

Here's a simple pie chart showing the distribution of categories:

You can copy this code below to create this chart in your project:

models:
  - name: pie-data
    args:
      - echo
      - |
        category,value
        A,30
        B,20
        C,50
traces:
  - name: Simple Pie Chart Trace
    model: ${ref(pie-data)}
    props:
      type: pie
      labels: ?{category}
      values: ?{value}
charts:
  - name: Simple Pie Chart
    traces:
      - ${ref(Simple Pie Chart Trace)}
    layout:
      title:
        text: Simple Pie Chart<br><sub>Distribution of Categories</sub>

This example demonstrates a pie chart with custom colors for each category:

Here's the code:

models:
  - name: pie-data-colors
    args:
      - echo
      - |
        category,value,color
        A,40,#1f77b4
        B,30,#ff7f0e
        C,30,#2ca02c
traces:
  - name: Pie Chart with Custom Colors Trace
    model: ${ref(pie-data-colors)}
    props:
      type: pie
      labels: ?{category}
      values: ?{value}
      marker:
        colors: ?{color}
charts:
  - name: Pie Chart with Custom Colors
    traces:
      - ${ref(Pie Chart with Custom Colors Trace)}
    layout:
      title:
        text: Pie Chart with Custom Colors<br><sub>Customized Coloring for Each Category</sub>

This example shows a pie chart with hover information that displays both the percentage and the value for each category:

Here's the code:

models:
  - name: pie-data-hover
    args:
      - echo
      - |
        category,value
        X,60
        Y,25
        Z,15
traces:
  - name: Pie Chart with Hover Info Trace
    model: ${ref(pie-data-hover)}
    props:
      type: pie
      labels: ?{category}
      values: ?{value}
      hoverinfo: "label+value+percent"
charts:
  - name: Pie Chart with Hover Info
    traces:
      - ${ref(Pie Chart with Hover Info Trace)}
    layout:
      title:
        text: Pie Chart with Hover Info<br><sub>Hover Info Showing Value and Percentage</sub>

A schema to validate plotly trace properties

Attributes

These attributes apply to traces where trace.props.type is set to pie. You would configure these attributes on the trace with the trace.props object.

automargin: boolean
customdata: array
customdatasrc: 'string' #(1)!
direction: any
dlabel: number
domain:
  column: integer
  row: integer
  x: array
  y: array
hole: number
hoverinfo: array
hoverinfosrc: 'string' #(2)!
hoverlabel:
  align: array
  alignsrc: 'string' #(3)!
  bgcolor: array
  bgcolorsrc: 'string' #(4)!
  bordercolor: array
  bordercolorsrc: 'string' #(5)!
  font:
    color: array
    colorsrc: 'string' #(6)!
    family: 'string | array' #(7)!
    familysrc: 'string' #(8)!
    lineposition: array
    linepositionsrc: 'string' #(9)!
    shadow: 'string | array' #(10)!
    shadowsrc: 'string' #(11)!
    size: array
    sizesrc: 'string' #(12)!
    style: array
    stylesrc: 'string' #(13)!
    textcase: array
    textcasesrc: 'string' #(14)!
    variant: array
    variantsrc: 'string' #(15)!
    weight: array
    weightsrc: 'string' #(16)!
  namelength: array
  namelengthsrc: 'string' #(17)!
hovertemplate: 'string | array' #(18)!
hovertemplatesrc: 'string' #(19)!
hovertext: 'string | array' #(20)!
hovertextsrc: 'string' #(21)!
ids: array
idssrc: 'string' #(22)!
insidetextfont:
  color: array
  colorsrc: 'string' #(23)!
  family: 'string | array' #(24)!
  familysrc: 'string' #(25)!
  lineposition: array
  linepositionsrc: 'string' #(26)!
  shadow: 'string | array' #(27)!
  shadowsrc: 'string' #(28)!
  size: array
  sizesrc: 'string' #(29)!
  style: array
  stylesrc: 'string' #(30)!
  textcase: array
  textcasesrc: 'string' #(31)!
  variant: array
  variantsrc: 'string' #(32)!
  weight: array
  weightsrc: 'string' #(33)!
insidetextorientation: any
label0: number
labels: array
labelssrc: 'string' #(34)!
legend: string
legendgroup: 'string' #(35)!
legendgrouptitle:
  font:
    color: any
    family: 'string' #(36)!
    lineposition: any
    shadow: 'string' #(37)!
    size: number
    style: any
    textcase: any
    variant: any
    weight: integer
  text: 'string' #(38)!
legendrank: number
legendwidth: number
marker:
  colors: array
  colorssrc: 'string' #(39)!
  line:
    color: array
    colorsrc: 'string' #(40)!
    width: array
    widthsrc: 'string' #(41)!
  pattern:
    bgcolor: array
    bgcolorsrc: 'string' #(42)!
    fgcolor: array
    fgcolorsrc: 'string' #(43)!
    fgopacity: number
    fillmode: any
    shape: array
    shapesrc: 'string' #(44)!
    size: array
    sizesrc: 'string' #(45)!
    solidity: array
    soliditysrc: 'string' #(46)!
metasrc: 'string' #(47)!
name: 'string' #(48)!
opacity: number
outsidetextfont:
  color: array
  colorsrc: 'string' #(49)!
  family: 'string | array' #(50)!
  familysrc: 'string' #(51)!
  lineposition: array
  linepositionsrc: 'string' #(52)!
  shadow: 'string | array' #(53)!
  shadowsrc: 'string' #(54)!
  size: array
  sizesrc: 'string' #(55)!
  style: array
  stylesrc: 'string' #(56)!
  textcase: array
  textcasesrc: 'string' #(57)!
  variant: array
  variantsrc: 'string' #(58)!
  weight: array
  weightsrc: 'string' #(59)!
pull: array
pullsrc: 'string' #(60)!
rotation: number
scalegroup: 'string' #(61)!
showlegend: boolean
sort: boolean
stream:
  maxpoints: number
  token: 'string' #(62)!
text: array
textfont:
  color: array
  colorsrc: 'string' #(63)!
  family: 'string | array' #(64)!
  familysrc: 'string' #(65)!
  lineposition: array
  linepositionsrc: 'string' #(66)!
  shadow: 'string | array' #(67)!
  shadowsrc: 'string' #(68)!
  size: array
  sizesrc: 'string' #(69)!
  style: array
  stylesrc: 'string' #(70)!
  textcase: array
  textcasesrc: 'string' #(71)!
  variant: array
  variantsrc: 'string' #(72)!
  weight: array
  weightsrc: 'string' #(73)!
textinfo: any
textposition: array
textpositionsrc: 'string' #(74)!
textsrc: 'string' #(75)!
texttemplate: 'string | array' #(76)!
texttemplatesrc: 'string' #(77)!
title:
  font:
    color: array
    colorsrc: 'string' #(78)!
    family: 'string | array' #(79)!
    familysrc: 'string' #(80)!
    lineposition: array
    linepositionsrc: 'string' #(81)!
    shadow: 'string | array' #(82)!
    shadowsrc: 'string' #(83)!
    size: array
    sizesrc: 'string' #(84)!
    style: array
    stylesrc: 'string' #(85)!
    textcase: array
    textcasesrc: 'string' #(86)!
    variant: array
    variantsrc: 'string' #(87)!
    weight: array
    weightsrc: 'string' #(88)!
  position: any
  text: 'string' #(89)!
type: pie
uid: 'string' #(90)!
values: array
valuessrc: 'string' #(91)!
visible: any
  1. Sets the source reference on Chart Studio Cloud for customdata.
  2. Sets the source reference on Chart Studio Cloud for hoverinfo.
  3. Sets the source reference on Chart Studio Cloud for align.
  4. Sets the source reference on Chart Studio Cloud for bgcolor.
  5. Sets the source reference on Chart Studio Cloud for bordercolor.
  6. Sets the source reference on Chart Studio Cloud for color.
  7. HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
  8. Sets the source reference on Chart Studio Cloud for family.
  9. Sets the source reference on Chart Studio Cloud for lineposition.
  10. Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
  11. Sets the source reference on Chart Studio Cloud for shadow.
  12. Sets the source reference on Chart Studio Cloud for size.
  13. Sets the source reference on Chart Studio Cloud for style.
  14. Sets the source reference on Chart Studio Cloud for textcase.
  15. Sets the source reference on Chart Studio Cloud for variant.
  16. Sets the source reference on Chart Studio Cloud for weight.
  17. Sets the source reference on Chart Studio Cloud for namelength.
  18. Template string used for rendering the information that appear on hover box. Note that this will override hoverinfo. Variables are inserted using %{variable}, for example "y: %{y}" as well as %{xother}, {%xother}, {%_xother}, {%xother_}. When showing info for several points, xother will be added to those with different x positions from the first point. An underscore before or after (x|y)other will add a space on that side, only when this field is shown. Numbers are formatted using d3-format's syntax %{variable:d3-format}, for example "Price: %{y:$.2f}". https://github.com/d3/d3-format/tree/v1.4.5#d3-format for details on the formatting syntax. Dates are formatted using d3-time-format's syntax %{variable|d3-time-format}, for example "Day: %{2019-01-01|%A}". https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format for details on the date formatting syntax. The variables available in hovertemplate are the ones emitted as event data described at this link https://plotly.com/javascript/plotlyjs-events/#event-data. Additionally, every attributes that can be specified per-point (the ones that are arrayOk: true) are available. Finally, the template string has access to variables label, color, value, percent and text. Anything contained in tag <extra> is displayed in the secondary box, for example "{fullData.name}". To hide the secondary box completely, use an empty tag <extra></extra>.
  19. Sets the source reference on Chart Studio Cloud for hovertemplate.
  20. Sets hover text elements associated with each sector. If a single string, the same string appears for all data points. If an array of string, the items are mapped in order of this trace's sectors. To be seen, trace hoverinfo must contain a text flag.
  21. Sets the source reference on Chart Studio Cloud for hovertext.
  22. Sets the source reference on Chart Studio Cloud for ids.
  23. Sets the source reference on Chart Studio Cloud for color.
  24. HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
  25. Sets the source reference on Chart Studio Cloud for family.
  26. Sets the source reference on Chart Studio Cloud for lineposition.
  27. Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
  28. Sets the source reference on Chart Studio Cloud for shadow.
  29. Sets the source reference on Chart Studio Cloud for size.
  30. Sets the source reference on Chart Studio Cloud for style.
  31. Sets the source reference on Chart Studio Cloud for textcase.
  32. Sets the source reference on Chart Studio Cloud for variant.
  33. Sets the source reference on Chart Studio Cloud for weight.
  34. Sets the source reference on Chart Studio Cloud for labels.
  35. Sets the legend group for this trace. Traces and shapes part of the same legend group hide/show at the same time when toggling legend items.
  36. HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
  37. Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
  38. Sets the title of the legend group.
  39. Sets the source reference on Chart Studio Cloud for colors.
  40. Sets the source reference on Chart Studio Cloud for color.
  41. Sets the source reference on Chart Studio Cloud for width.
  42. Sets the source reference on Chart Studio Cloud for bgcolor.
  43. Sets the source reference on Chart Studio Cloud for fgcolor.
  44. Sets the source reference on Chart Studio Cloud for shape.
  45. Sets the source reference on Chart Studio Cloud for size.
  46. Sets the source reference on Chart Studio Cloud for solidity.
  47. Sets the source reference on Chart Studio Cloud for meta.
  48. Sets the trace name. The trace name appears as the legend item and on hover.
  49. Sets the source reference on Chart Studio Cloud for color.
  50. HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
  51. Sets the source reference on Chart Studio Cloud for family.
  52. Sets the source reference on Chart Studio Cloud for lineposition.
  53. Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
  54. Sets the source reference on Chart Studio Cloud for shadow.
  55. Sets the source reference on Chart Studio Cloud for size.
  56. Sets the source reference on Chart Studio Cloud for style.
  57. Sets the source reference on Chart Studio Cloud for textcase.
  58. Sets the source reference on Chart Studio Cloud for variant.
  59. Sets the source reference on Chart Studio Cloud for weight.
  60. Sets the source reference on Chart Studio Cloud for pull.
  61. If there are multiple pie charts that should be sized according to their totals, link them by providing a non-empty group id here shared by every trace in the same group.
  62. The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
  63. Sets the source reference on Chart Studio Cloud for color.
  64. HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
  65. Sets the source reference on Chart Studio Cloud for family.
  66. Sets the source reference on Chart Studio Cloud for lineposition.
  67. Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
  68. Sets the source reference on Chart Studio Cloud for shadow.
  69. Sets the source reference on Chart Studio Cloud for size.
  70. Sets the source reference on Chart Studio Cloud for style.
  71. Sets the source reference on Chart Studio Cloud for textcase.
  72. Sets the source reference on Chart Studio Cloud for variant.
  73. Sets the source reference on Chart Studio Cloud for weight.
  74. Sets the source reference on Chart Studio Cloud for textposition.
  75. Sets the source reference on Chart Studio Cloud for text.
  76. Template string used for rendering the information text that appear on points. Note that this will override textinfo. Variables are inserted using %{variable}, for example "y: %{y}". Numbers are formatted using d3-format's syntax %{variable:d3-format}, for example "Price: %{y:$.2f}". https://github.com/d3/d3-format/tree/v1.4.5#d3-format for details on the formatting syntax. Dates are formatted using d3-time-format's syntax %{variable|d3-time-format}, for example "Day: %{2019-01-01|%A}". https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format for details on the date formatting syntax. Every attributes that can be specified per-point (the ones that are arrayOk: true) are available. Finally, the template string has access to variables label, color, value, percent and text.
  77. Sets the source reference on Chart Studio Cloud for texttemplate.
  78. Sets the source reference on Chart Studio Cloud for color.
  79. HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
  80. Sets the source reference on Chart Studio Cloud for family.
  81. Sets the source reference on Chart Studio Cloud for lineposition.
  82. Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
  83. Sets the source reference on Chart Studio Cloud for shadow.
  84. Sets the source reference on Chart Studio Cloud for size.
  85. Sets the source reference on Chart Studio Cloud for style.
  86. Sets the source reference on Chart Studio Cloud for textcase.
  87. Sets the source reference on Chart Studio Cloud for variant.
  88. Sets the source reference on Chart Studio Cloud for weight.
  89. Sets the title of the chart. If it is empty, no title is displayed.
  90. Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
  91. Sets the source reference on Chart Studio Cloud for values.