bar

Bars standing at the names of one axis, each reaching to its value along the other.

Only withxypolarxyzplane
Stacked bars for Monday to Friday, a teal bar standing on each blue one.Stacked bars for Monday to Friday, a teal bar standing on each blue one.

#Names and values

bar(x: North, South, East; y: 42, 31, 55) stands a bar at each name, reaching from the baseline to its value. x and y are series, as a scatter's are: paired by position, written out or bound whole (bar(x: #sales.region; y: #sales.revenue)). Exactly one axis is ruled in names — by the names in its series under auto, or by x format: / y format: — and the other is the value axis, which always reaches the baseline. Which axis holds the names is the orientation: names on y lay the bars out sideways.

bar(x: 1, 2, 3; y: 42, 31, 55)

[canvas/bar-axes]'bar' stands on a categorical axis, and neither axis is one — name the categories in 'x:' or 'y:', or rule an axis with 'x format:' / 'y format:'

Bars on a numeric axis are a histogram, whose widths are bin edges. A list in colour is cycled bar by bar, so one bar is picked out by its place in the list — colour: grey, grey, grey, red, grey colours the fourth. A map colours bars by their data: colour: #sales.region -> (North: orange) picks out the bar standing at North, the rest keeping the default blue, and colour: #self.value -> (..<0: red; 0..: teal) the bars by their values (Styling marks from data). show-labels writes each value at its bar's end.

#Several bars at one name

Each bar written is one series. Where several have a bar at the same name they split the band there in source order; where only one does, its bar takes the band whole. band is the share of the band the bars at a name fill. stack stands a bar's values on top of the bar written before it, name by name, so a run of stacked bars builds one column. A hidden bar takes no share of the band.

Revenue in £k for North, South, East and West: grey bars for 2023 and blue bars for 2024.Revenue in £k for North, South, East and West: grey bars for 2023 and blue bars for 2024.
graph{
    @data#sales{
        region | y2023 | y2024
        North  | 38.0  | 42.1
        South  | 33.5  | 31.4
        East   | 47.2  | 55.0
        West   | 26.1  | 27.8
    }

    bar(x: #sales.region; y: #sales.y2023; colour: grey; label: 2023)
    bar(x: #sales.region; y: #sales.y2024; colour: blue; label: 2024)
}(
    y axis label: revenue (£k)
)

#Bars over periods

Long-format data has one row per name per period. slice names the period column, and the bars show the period that the scene's parameter over that column holds — a slider or selector whose column: is the same column. A numeric period column glides between the periods either side; a column of names selects one. @data covers the shape of the rows.

graph{
    slider:t(column: #sales.year; name: Year)
    bar(x: #sales.region; y: #sales.revenue; slice: #sales.year)
}

#Error bars

error draws a capped bar through the middle of each bar's end, along the value axis, in the bar's edge colour. It is written as a scatter's is: a half-width per bar, such as a standard deviation, or the interval's two ends, error: #trials.lo .. #trials.hi.

Teal bars of mean yield for four feeds — Control, Nitrogen, Compost and Both — each with a capped error bar through its top spanning one standard deviation either side.Teal bars of mean yield for four feeds — Control, Nitrogen, Compost and Both — each with a capped error bar through its top spanning one standard deviation either side.
graph{
    @data#yield{
        feed     | mean | sd
        Control  | 4.1  | 0.6
        Nitrogen | 5.6  | 0.8
        Compost  | 5.0  | 0.5
        Both     | 6.3  | 0.9
    }

    bar(x: #yield.feed; y: #yield.mean; error: #yield.sd; colour: teal)
}(
    y axis label: yield (t/ha)
)

A stack bar ends at a running total rather than at its own reading, so it takes no error; neither does a rose or a column in space (canvas/plane-attribute).

#Roses and columns

On the polar plane a bar chart is a rose: the bars stand at names on theta and reach out along r, so theta must be ruled in names (canvas/bar-axes). In space, bar(x: …; y: …; z: …) stands a column at each (x, y) on the floor, as tall as its z; either floor axis may be names or numbers, and stack and show-labels are refused.


#Attributes

On any plane
reAnimatable
On the argand plane, the readings' real parts, one per reading — numbers written out or a column — paired with im by position.
imAnimatable
On the argand plane, the readings' imaginary parts, paired with re by position.
slice
The column this mark is SLICED by — long-format data, one row per thing per slice, showing the one the scene's parameter over that column holds. A column with a number line interpolates, so a reader stopped between two values sees half way; a column of names selects the rows carrying the name they picked.
colour
The bars' colour: one colour, a list cycled bar by bar, or an expression giving a colour per bar from a column or #self.value, the bar's value. colour: #self.value -> (..<0: red; 0..: blue) bands the bars by value; a map keyed by names applied to a column gives categories, colour: #sales.region -> (North: teal; otherwise: grey).
colour-style
Also written: color
Defaultblue
opacity
How solid each bar is, 0 to 1: one opacity, a list bar by bar, or an expression giving one per bar from a column or #self.value.
opacity-style
Default1
bandAnimatable
The share of the band at each name that the bars there fill, 0–1, divided between them. In space, the share of its room a column fills along both floor axes.
Default0.7
stack
Stand this bar's values on top of the bar written before it, name by name, in that bar's share of the band; a run of stacked bars builds one column. Refused in space.
Also written: stacked
Defaultfalse
show-labelsAnimatable
Write each bar's value at its end. Refused in space.
Also written: labels
Defaultfalse
label
Text drawn beside the element — rich text, so $maths$ and inline formatting render. Fades and draws with the element.
hiddenAnimatable
Declared but not drawn. Animatable — hidden: true !cue.to{false}(at: 2) reveals it — and unlike a cue, a hidden element still frames the plot, so the axes do not jump when it appears.
Defaultfalse
lock
Keeps the reader from editing this element on an editable: graph. Nothing at all on a graph that is not editable.
Also written: locked
Defaultfalse
text-sizeAnimatable
Text size.
Default20
layerAnimatable
Paint order among the marks: a higher layer is drawn later, on top; equal or omitted, the marks stack in document order (later on top). Written z: before the argand plane took that letter for its coordinate.
group
The groups this bar belongs to, comma-separated: group: Treated, Projected. It is drawn in the colour of the first group that has one, over its own colour:, and the footer's key names every group. A stroke the graph's key: gives a group does not change it.
Only withxyplane
xImplicitAnimatable
The readings’ x values: names, numbers, or a dataset column (#sales.region). Paired with y by position; a pair either axis cannot read is dropped whole.
Can be written as shorthand: bar:value
yAnimatable
The readings’ y values, paired with x by position.
errorAnimatable
Each bar's uncertainty, drawn as a capped bar through the middle of its end along the value axis, in the bar's edge colour. Each entry is a half-width, or the interval's two ends — error: #trials.lo .. #trials.hi, or 0.7..1.1, 0.8..1.3 — as a scatter's error: takes. Refused on a stack: bar, whose end is a running total rather than its own reading.
Only withpolarplane
rAnimatable
On the polar plane, the readings' distances from the origin, paired with theta by position. A rose reaches each bar out to its reading.
thetaAnimatable
On the polar plane, the readings' angles in radians (60deg for degrees), paired with r by position; names on a categorical theta. A rose stands its bars at names — theta: North, East, South, West, or theta format:.
Only withxyzplane
xImplicitAnimatable
The readings’ x values: names, numbers, or a dataset column (#sales.region). Paired with y by position; a pair either axis cannot read is dropped whole.
Can be written as shorthand: bar:value
yAnimatable
The readings’ y values, paired with x by position.
zAnimatable
In space, the height of each column, paired by position with x and y: written out, or a column bound whole (#sales.amount).

#Derived attributes

Computed while the element renders — read one with #id.name in attribute position or {{#id.name}} in prose, never set.

valueDerived
Each bar's value, one per bar, which a style attribute follows as #self.value: colour: #self.value -> (..<0: red; 0..: teal).
totalDerived
The sum of this mark's own bar values — a stack: bar's own segments, not the height of the column it tops — following a slice or slider, in the value axis's units, each mark of a group counting only its own; in space, of its columns' heights; a dash with none.
maxDerived
The largest of this mark's own bar values — a stack: bar's own segments, not the height of the column it tops — following a slice or slider, in the value axis's units; in space, of its columns' heights; a dash with none.
minDerived
The smallest of this mark's own bar values — a stack: bar's own segments, not the height of the column it tops — following a slice or slider, in the value axis's units; in space, of its columns' heights; a dash with none.
countDerived
The number of bars this mark draws (columns, in space), counting its own only — a stack: bar's segments, never the column it tops, and each mark of a group side by side separately; 0 with none.

#Allowed in

#Examples

Grey bars for Monday to Friday with Thursday, the tallest, in red.Grey bars for Monday to Friday with Thursday, the tallest, in red.
graph{
    bar(
        x: Mon, Tue, Wed, Thu, Fri
        y: 12, 19, 15, 22, 17
        colour: grey, grey, grey, red, grey
    )
}
A bar chart in space: tea, coffee and juice sales for North, South and East as columns standing on a floor of names, East's coffee the tallest.A bar chart in space: tea, coffee and juice sales for North, South and East as columns standing on a floor of names, East's coffee the tallest.
graph:xyz{
    bar(
        x: North, South, East, North, South, East, North, South, East
        y: Tea, Tea, Tea, Coffee, Coffee, Coffee, Juice, Juice, Juice
        z: 12, 9, 14, 18, 15, 22, 7, 10, 6
        colour: teal, teal, teal, orange, orange, orange, purple, purple, purple
    )
}(
    z axis label: sales
    view: (-50, 25)
)

#Writing guidance

  • Framing a readable graph — When to write a domain, the defaults left alone, naming a series, the ticks the prose reads, and one meaning per hue.

Last updated