Skip to content

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
  1. 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.
  2. 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.
  3. Sets the source reference on Chart Studio Cloud for base.
  4. Sets the source reference on Chart Studio Cloud for customdata.
  5. Sets the source reference on Chart Studio Cloud for arrayminus.
  6. Sets the source reference on Chart Studio Cloud for array.
  7. Sets the source reference on Chart Studio Cloud for arrayminus.
  8. Sets the source reference on Chart Studio Cloud for array.
  9. Sets the source reference on Chart Studio Cloud for hoverinfo.
  10. Sets the source reference on Chart Studio Cloud for align.
  11. Sets the source reference on Chart Studio Cloud for bgcolor.
  12. Sets the source reference on Chart Studio Cloud for bordercolor.
  13. Sets the source reference on Chart Studio Cloud for color.
  14. 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.
  15. Sets the source reference on Chart Studio Cloud for family.
  16. Sets the source reference on Chart Studio Cloud for lineposition.
  17. 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.
  18. Sets the source reference on Chart Studio Cloud for shadow.
  19. Sets the source reference on Chart Studio Cloud for size.
  20. Sets the source reference on Chart Studio Cloud for style.
  21. Sets the source reference on Chart Studio Cloud for textcase.
  22. Sets the source reference on Chart Studio Cloud for variant.
  23. Sets the source reference on Chart Studio Cloud for weight.
  24. Sets the source reference on Chart Studio Cloud for namelength.
  25. 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 value and label. 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>.
  26. Sets the source reference on Chart Studio Cloud for hovertemplate.
  27. 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.
  28. Sets the source reference on Chart Studio Cloud for hovertext.
  29. Sets the source reference on Chart Studio Cloud for ids.
  30. Sets the source reference on Chart Studio Cloud for color.
  31. 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.
  32. Sets the source reference on Chart Studio Cloud for family.
  33. Sets the source reference on Chart Studio Cloud for lineposition.
  34. 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.
  35. Sets the source reference on Chart Studio Cloud for shadow.
  36. Sets the source reference on Chart Studio Cloud for size.
  37. Sets the source reference on Chart Studio Cloud for style.
  38. Sets the source reference on Chart Studio Cloud for textcase.
  39. Sets the source reference on Chart Studio Cloud for variant.
  40. Sets the source reference on Chart Studio Cloud for weight.
  41. 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.
  42. 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.
  43. 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.
  44. Sets the title of the legend group.
  45. 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.
  46. 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.
  47. 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
  48. Sets a tick label prefix.
  49. Sets a tick label suffix.
  50. Sets the source reference on Chart Studio Cloud for ticktext.
  51. Sets the source reference on Chart Studio Cloud for tickvals.
  52. 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.
  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 title of the color bar.
  55. Sets the source reference on Chart Studio Cloud for color.
  56. Sets the source reference on Chart Studio Cloud for color.
  57. Sets the source reference on Chart Studio Cloud for width.
  58. Sets the source reference on Chart Studio Cloud for opacity.
  59. Sets the source reference on Chart Studio Cloud for bgcolor.
  60. Sets the source reference on Chart Studio Cloud for fgcolor.
  61. Sets the source reference on Chart Studio Cloud for shape.
  62. Sets the source reference on Chart Studio Cloud for size.
  63. Sets the source reference on Chart Studio Cloud for solidity.
  64. Sets the source reference on Chart Studio Cloud for meta.
  65. Sets the trace name. The trace name appears as the legend item and on hover.
  66. 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.
  67. Sets the source reference on Chart Studio Cloud for offset.
  68. Sets the source reference on Chart Studio Cloud for color.
  69. 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.
  70. Sets the source reference on Chart Studio Cloud for family.
  71. Sets the source reference on Chart Studio Cloud for lineposition.
  72. 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.
  73. Sets the source reference on Chart Studio Cloud for shadow.
  74. Sets the source reference on Chart Studio Cloud for size.
  75. Sets the source reference on Chart Studio Cloud for style.
  76. Sets the source reference on Chart Studio Cloud for textcase.
  77. Sets the source reference on Chart Studio Cloud for variant.
  78. Sets the source reference on Chart Studio Cloud for weight.
  79. The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
  80. 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.
  81. Sets the source reference on Chart Studio Cloud for color.
  82. 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.
  83. Sets the source reference on Chart Studio Cloud for family.
  84. Sets the source reference on Chart Studio Cloud for lineposition.
  85. 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.
  86. Sets the source reference on Chart Studio Cloud for shadow.
  87. Sets the source reference on Chart Studio Cloud for size.
  88. Sets the source reference on Chart Studio Cloud for style.
  89. Sets the source reference on Chart Studio Cloud for textcase.
  90. Sets the source reference on Chart Studio Cloud for variant.
  91. Sets the source reference on Chart Studio Cloud for weight.
  92. Sets the source reference on Chart Studio Cloud for textposition.
  93. Sets the source reference on Chart Studio Cloud for text.
  94. 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 value and label.
  95. Sets the source reference on Chart Studio Cloud for texttemplate.
  96. Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
  97. Sets the source reference on Chart Studio Cloud for width.
  98. 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 using xaxis.hoverformat.
  99. Sets the source reference on Chart Studio Cloud for x.
  100. 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 using yaxis.hoverformat.
  101. Sets the source reference on Chart Studio Cloud for y.