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
- Sets the source reference on Chart Studio Cloud for
customdata
. - Sets the source reference on Chart Studio Cloud for
hoverinfo
. - Sets the source reference on Chart Studio Cloud for
align
. - Sets the source reference on Chart Studio Cloud for
bgcolor
. - Sets the source reference on Chart Studio Cloud for
bordercolor
. - Sets the source reference on Chart Studio Cloud for
color
. - 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.
- Sets the source reference on Chart Studio Cloud for
family
. - Sets the source reference on Chart Studio Cloud for
lineposition
. - 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.
- Sets the source reference on Chart Studio Cloud for
shadow
. - Sets the source reference on Chart Studio Cloud for
size
. - Sets the source reference on Chart Studio Cloud for
style
. - Sets the source reference on Chart Studio Cloud for
textcase
. - Sets the source reference on Chart Studio Cloud for
variant
. - Sets the source reference on Chart Studio Cloud for
weight
. - Sets the source reference on Chart Studio Cloud for
namelength
. - 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 inhovertemplate
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 arearrayOk: true
) are available. Finally, the template string has access to variableslabel
,color
,value
,percent
andtext
. 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>
. - Sets the source reference on Chart Studio Cloud for
hovertemplate
. - 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. - Sets the source reference on Chart Studio Cloud for
hovertext
. - Sets the source reference on Chart Studio Cloud for
ids
. - Sets the source reference on Chart Studio Cloud for
color
. - 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.
- Sets the source reference on Chart Studio Cloud for
family
. - Sets the source reference on Chart Studio Cloud for
lineposition
. - 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.
- Sets the source reference on Chart Studio Cloud for
shadow
. - Sets the source reference on Chart Studio Cloud for
size
. - Sets the source reference on Chart Studio Cloud for
style
. - Sets the source reference on Chart Studio Cloud for
textcase
. - Sets the source reference on Chart Studio Cloud for
variant
. - Sets the source reference on Chart Studio Cloud for
weight
. - Sets the source reference on Chart Studio Cloud for
labels
. - 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.
- 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.
- 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.
- Sets the title of the legend group.
- Sets the source reference on Chart Studio Cloud for
colors
. - Sets the source reference on Chart Studio Cloud for
color
. - Sets the source reference on Chart Studio Cloud for
width
. - Sets the source reference on Chart Studio Cloud for
bgcolor
. - Sets the source reference on Chart Studio Cloud for
fgcolor
. - Sets the source reference on Chart Studio Cloud for
shape
. - Sets the source reference on Chart Studio Cloud for
size
. - Sets the source reference on Chart Studio Cloud for
solidity
. - Sets the source reference on Chart Studio Cloud for
meta
. - Sets the trace name. The trace name appears as the legend item and on hover.
- Sets the source reference on Chart Studio Cloud for
color
. - 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.
- Sets the source reference on Chart Studio Cloud for
family
. - Sets the source reference on Chart Studio Cloud for
lineposition
. - 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.
- Sets the source reference on Chart Studio Cloud for
shadow
. - Sets the source reference on Chart Studio Cloud for
size
. - Sets the source reference on Chart Studio Cloud for
style
. - Sets the source reference on Chart Studio Cloud for
textcase
. - Sets the source reference on Chart Studio Cloud for
variant
. - Sets the source reference on Chart Studio Cloud for
weight
. - Sets the source reference on Chart Studio Cloud for
pull
. - 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.
- The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
- Sets the source reference on Chart Studio Cloud for
color
. - 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.
- Sets the source reference on Chart Studio Cloud for
family
. - Sets the source reference on Chart Studio Cloud for
lineposition
. - 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.
- Sets the source reference on Chart Studio Cloud for
shadow
. - Sets the source reference on Chart Studio Cloud for
size
. - Sets the source reference on Chart Studio Cloud for
style
. - Sets the source reference on Chart Studio Cloud for
textcase
. - Sets the source reference on Chart Studio Cloud for
variant
. - Sets the source reference on Chart Studio Cloud for
weight
. - Sets the source reference on Chart Studio Cloud for
textposition
. - Sets the source reference on Chart Studio Cloud for
text
. - 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 arearrayOk: true
) are available. Finally, the template string has access to variableslabel
,color
,value
,percent
andtext
. - Sets the source reference on Chart Studio Cloud for
texttemplate
. - Sets the source reference on Chart Studio Cloud for
color
. - 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.
- Sets the source reference on Chart Studio Cloud for
family
. - Sets the source reference on Chart Studio Cloud for
lineposition
. - 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.
- Sets the source reference on Chart Studio Cloud for
shadow
. - Sets the source reference on Chart Studio Cloud for
size
. - Sets the source reference on Chart Studio Cloud for
style
. - Sets the source reference on Chart Studio Cloud for
textcase
. - Sets the source reference on Chart Studio Cloud for
variant
. - Sets the source reference on Chart Studio Cloud for
weight
. - Sets the title of the chart. If it is empty, no title is displayed.
- Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
- Sets the source reference on Chart Studio Cloud for
values
.