Bar
Overview
The bar trace type is used to display data as bars.
You have pretty broad control over the appearance of the bars via the marker
attributes. You can set the fill color, opacity, pattern, line color, width, etc. You can also configure display the bars as either grouped or stacked.
Common Uses
- Categorical Data Comparison: Visualizing data across distinct categories (e.g., sales by product type).
- Grouped Bar Charts: Comparing multiple series side by side (e.g., monthly sales by region).
- Stacked Bar Charts: Showing cumulative data (e.g., revenue breakdown by product within a year).
- Horizontal Bar Charts: Comparing data where horizontal labels are more readable (e.g., ranking of countries by population).
- Time-Series Data (Categorical): Displaying data changes over time with categories as the x-axis (e.g., yearly revenue growth by product).
Checkout the Attributes for the full set of configuration options
Examples
Common Configurations
Here's a really simple bar chart:
You can copy this code below to create this chart in your project:
models:
- name: monty-python-quest-data
args:
- curl
- "https://raw.githubusercontent.com/visivo-io/data/refs/heads/main/monty_python_quests.csv"
traces:
- name: Count Enemies Encountered by Knight
model: ${ref(monty-python-quest-data)}
cohort_on: "person"
props:
type: bar
x: ?{enemy_encountered}
y: ?{ count(*) }
text: ?{ count(*) }
order_by:
- ?{ count(*) desc}
charts:
- name: Count Times Enemy Was Encountered by Knight
traces:
- ${ref(Count Enemies Encountered by Knight)}
layout:
title:
text: Cohorted Bar<br><sub>The Number of Times an Enemy was Enountered on a Quest by Knight</sub>
You can use the trace.cohort_on
key to create facets in your bar chart.
Here's the code:
models:
- name: monty-python-quest-data
args:
- curl
- "https://raw.githubusercontent.com/visivo-io/data/refs/heads/main/monty_python_quests.csv"
traces:
- name: Count Enemies Encountered by Knight
model: ${ref(monty-python-quest-data)}
cohort_on: "person"
props:
type: bar
x: ?{enemy_encountered}
y: ?{ count(*) }
text: ?{ count(*) }
order_by:
- ?{ count(*) desc}
charts:
- name: Count Times Enemy Was Encountered by Knight
traces:
- ${ref(Count Enemies Encountered by Knight)}
layout:
title:
text: Cohorted Bar<br><sub>The Number of Times an Enemy was Enountered on a Quest by Knight</sub>
It can be useful to view some data horizontally.
Here's the code:
models:
- name: monty-python-quest-data-h
args:
- curl
- "https://raw.githubusercontent.com/visivo-io/data/refs/heads/main/monty_python_quests.csv"
traces:
- name: Count Enemies Encountered by Knight H
model: ${ref(monty-python-quest-data-h)}
cohort_on: "person"
props:
type: bar
y: ?{enemy_encountered}
x: ?{ count(*) }
text: ?{ count(*) }
textposition: outside
textfont:
size: 15
orientation: h
order_by:
- ?{ count(*) desc}
charts:
- name: Count Times Enemy Was Encountered by Knight H
traces:
- ${ref(Count Enemies Encountered by Knight H)}
layout:
title:
text: Horizontal Cohorted Bar<br><sub>The Number of Times an Enemy was Enountered on a Quest by Knight</sub>
margin:
l: 160
A schema to validate plotly trace properties
Attributes
These attributes apply to traces where trace.props.type
is set to bar
. You would configure these attributes on the trace with the trace.props
object.
alignmentgroup: 'string' #(1)!
base: 'array' #(2)!
basesrc: 'string' #(3)!
cliponaxis: boolean
constraintext: any
customdata: array
customdatasrc: 'string' #(4)!
dx: number
dy: number
error_x:
array: array
arrayminus: array
arrayminussrc: 'string' #(5)!
arraysrc: 'string' #(6)!
color: any
copy_ystyle: boolean
symmetric: boolean
thickness: number
traceref: integer
tracerefminus: integer
type: any
value: number
valueminus: number
visible: boolean
width: number
error_y:
array: array
arrayminus: array
arrayminussrc: 'string' #(7)!
arraysrc: 'string' #(8)!
color: any
symmetric: boolean
thickness: number
traceref: integer
tracerefminus: integer
type: any
value: number
valueminus: number
visible: boolean
width: number
hoverinfo: array
hoverinfosrc: 'string' #(9)!
hoverlabel:
align: array
alignsrc: 'string' #(10)!
bgcolor: array
bgcolorsrc: 'string' #(11)!
bordercolor: array
bordercolorsrc: 'string' #(12)!
font:
color: array
colorsrc: 'string' #(13)!
family: 'string | array' #(14)!
familysrc: 'string' #(15)!
lineposition: array
linepositionsrc: 'string' #(16)!
shadow: 'string | array' #(17)!
shadowsrc: 'string' #(18)!
size: array
sizesrc: 'string' #(19)!
style: array
stylesrc: 'string' #(20)!
textcase: array
textcasesrc: 'string' #(21)!
variant: array
variantsrc: 'string' #(22)!
weight: array
weightsrc: 'string' #(23)!
namelength: array
namelengthsrc: 'string' #(24)!
hovertemplate: 'string | array' #(25)!
hovertemplatesrc: 'string' #(26)!
hovertext: 'string | array' #(27)!
hovertextsrc: 'string' #(28)!
ids: array
idssrc: 'string' #(29)!
insidetextanchor: any
insidetextfont:
color: array
colorsrc: 'string' #(30)!
family: 'string | array' #(31)!
familysrc: 'string' #(32)!
lineposition: array
linepositionsrc: 'string' #(33)!
shadow: 'string | array' #(34)!
shadowsrc: 'string' #(35)!
size: array
sizesrc: 'string' #(36)!
style: array
stylesrc: 'string' #(37)!
textcase: array
textcasesrc: 'string' #(38)!
variant: array
variantsrc: 'string' #(39)!
weight: array
weightsrc: 'string' #(40)!
legend: string
legendgroup: 'string' #(41)!
legendgrouptitle:
font:
color: any
family: 'string' #(42)!
lineposition: any
shadow: 'string' #(43)!
size: number
style: any
textcase: any
variant: any
weight: integer
text: 'string' #(44)!
legendrank: number
legendwidth: number
marker:
autocolorscale: boolean
cauto: boolean
cmax: number
cmid: number
cmin: number
color: array
coloraxis: string
colorbar:
bgcolor: any
bordercolor: any
borderwidth: number
exponentformat: any
len: number
lenmode: any
minexponent: number
nticks: integer
orientation: any
outlinecolor: any
outlinewidth: number
separatethousands: boolean
showexponent: any
showticklabels: boolean
showtickprefix: any
showticksuffix: any
thickness: number
thicknessmode: any
tickangle: number
tickcolor: any
tickfont:
color: any
family: 'string' #(45)!
lineposition: any
shadow: 'string' #(46)!
size: number
style: any
textcase: any
variant: any
weight: integer
tickformat: 'string' #(47)!
tickformatstops: array
ticklabeloverflow: any
ticklabelposition: any
ticklabelstep: integer
ticklen: number
tickmode: any
tickprefix: 'string' #(48)!
ticks: any
ticksuffix: 'string' #(49)!
ticktext: array
ticktextsrc: 'string' #(50)!
tickvals: array
tickvalssrc: 'string' #(51)!
tickwidth: number
title:
font:
color: any
family: 'string' #(52)!
lineposition: any
shadow: 'string' #(53)!
size: number
style: any
textcase: any
variant: any
weight: integer
side: any
text: 'string' #(54)!
x: number
xanchor: any
xpad: number
xref: any
y: number
yanchor: any
ypad: number
yref: any
colorscale: any
colorsrc: 'string' #(55)!
line:
autocolorscale: boolean
cauto: boolean
cmax: number
cmid: number
cmin: number
color: array
coloraxis: string
colorscale: any
colorsrc: 'string' #(56)!
reversescale: boolean
width: array
widthsrc: 'string' #(57)!
opacity: array
opacitysrc: 'string' #(58)!
pattern:
bgcolor: array
bgcolorsrc: 'string' #(59)!
fgcolor: array
fgcolorsrc: 'string' #(60)!
fgopacity: number
fillmode: any
shape: array
shapesrc: 'string' #(61)!
size: array
sizesrc: 'string' #(62)!
solidity: array
soliditysrc: 'string' #(63)!
reversescale: boolean
showscale: boolean
metasrc: 'string' #(64)!
name: 'string' #(65)!
offset: array
offsetgroup: 'string' #(66)!
offsetsrc: 'string' #(67)!
opacity: number
orientation: any
outsidetextfont:
color: array
colorsrc: 'string' #(68)!
family: 'string | array' #(69)!
familysrc: 'string' #(70)!
lineposition: array
linepositionsrc: 'string' #(71)!
shadow: 'string | array' #(72)!
shadowsrc: 'string' #(73)!
size: array
sizesrc: 'string' #(74)!
style: array
stylesrc: 'string' #(75)!
textcase: array
textcasesrc: 'string' #(76)!
variant: array
variantsrc: 'string' #(77)!
weight: array
weightsrc: 'string' #(78)!
selected:
marker:
color: any
opacity: number
textfont:
color: any
showlegend: boolean
stream:
maxpoints: number
token: 'string' #(79)!
text: 'string | array' #(80)!
textangle: number
textfont:
color: array
colorsrc: 'string' #(81)!
family: 'string | array' #(82)!
familysrc: 'string' #(83)!
lineposition: array
linepositionsrc: 'string' #(84)!
shadow: 'string | array' #(85)!
shadowsrc: 'string' #(86)!
size: array
sizesrc: 'string' #(87)!
style: array
stylesrc: 'string' #(88)!
textcase: array
textcasesrc: 'string' #(89)!
variant: array
variantsrc: 'string' #(90)!
weight: array
weightsrc: 'string' #(91)!
textposition: array
textpositionsrc: 'string' #(92)!
textsrc: 'string' #(93)!
texttemplate: 'string | array' #(94)!
texttemplatesrc: 'string' #(95)!
type: bar
uid: 'string' #(96)!
unselected:
marker:
color: any
opacity: number
textfont:
color: any
visible: any
width: array
widthsrc: 'string' #(97)!
x: array
xaxis: string
xcalendar: any
xhoverformat: 'string' #(98)!
xperiodalignment: any
xsrc: 'string' #(99)!
y: array
yaxis: string
ycalendar: any
yhoverformat: 'string' #(100)!
yperiodalignment: any
ysrc: 'string' #(101)!
zorder: integer
- Set several traces linked to the same position axis or matching axes to the same alignmentgroup. This controls whether bars compute their positional range dependently or independently.
- Sets where the bar base is drawn (in position axis units). In stack or relative barmode, traces that set base will be excluded and drawn in overlay mode instead.
- Sets the source reference on Chart Studio Cloud for
base
. - Sets the source reference on Chart Studio Cloud for
customdata
. - Sets the source reference on Chart Studio Cloud for
arrayminus
. - Sets the source reference on Chart Studio Cloud for
array
. - Sets the source reference on Chart Studio Cloud for
arrayminus
. - Sets the source reference on Chart Studio Cloud for
array
. - 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 variablesvalue
andlabel
. 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 (x,y) pair. If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to the this trace's (x,y) coordinates. 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 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.
- 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 tick label formatting rule using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: %h for half of the year as a decimal number as well as %{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46
- Sets a tick label prefix.
- Sets a tick label suffix.
- Sets the source reference on Chart Studio Cloud for
ticktext
. - Sets the source reference on Chart Studio Cloud for
tickvals
. - 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 color bar.
- Sets the source reference on Chart Studio Cloud for
color
. - 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
opacity
. - 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.
- Set several traces linked to the same position axis or matching axes to the same offsetgroup where bars of the same position coordinate will line up.
- Sets the source reference on Chart Studio Cloud for
offset
. - 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
. - 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 text elements associated with each (x,y) pair. If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to the this trace's (x,y) coordinates. If trace
hoverinfo
contains a text flag and hovertext is not set, these elements will be seen in the hover labels. - 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 variablesvalue
andlabel
. - Sets the source reference on Chart Studio Cloud for
texttemplate
. - 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
width
. - Sets the hover text formatting rulefor
x
using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: %h for half of the year as a decimal number as well as %{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46By default the values are formatted usingxaxis.hoverformat
. - Sets the source reference on Chart Studio Cloud for
x
. - Sets the hover text formatting rulefor
y
using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: %h for half of the year as a decimal number as well as %{n}f for fractional seconds with n digits. For example, 2016-10-13 09:15:23.456 with tickformat %H~%M~%S.%2f would display 09~15~23.46By default the values are formatted usingyaxis.hoverformat
. - Sets the source reference on Chart Studio Cloud for
y
.