Charts
A chart presents a table visually. Use queries to change the table shape, then feed it into chart verbs.
Chart
First prepare the data to the desired shape, then feed the table to chart.xx with horizontal and vertical axes:
If the table only has one numeric column and one non-numeric column, the axes can be omitted:
A chart is an ordinary value. It can be named, passed around, or returned from a function:
:chart
Channels
A channel connects a table column to a visual role. In x = Month y = Revenue color = Region, the channel names are x, y, and color. Here are the available channels:
• x and y choose horizontal and vertical position.
• color separates groups by color and usually creates a legend.
• size scales point size.
• text adds data labels and tooltip detail.
• y1 and y2 set the lower and upper edges of a band.
• facet, x-facet, and y-facet split data into small charts.
Use facet for a vertical series of panels, or x-facet and y-facet for a grid.
Categories and trends
Choose a mark by the question the chart should answer: bars compare categories, lines and areas show ordered change, and points show relationships between two measures.
Bar
chart.bar compares categories and values with rectangular marks; use color and stack = true to show contributions within each category.
Line
chart.line connects ordered observations and is the usual choice for a trend over time.
Area
chart.area draws a filled line series; lower opacity when the fill should stay visually light.
Point
chart.point draws independent points for scatter plots, dot plots, and comparisons using several channels.
Distributions
Distribution charts answer questions about the spread of many observations.
Histogram
chart.histogram divides one numeric or duration column into buckets and counts the observations in each bucket.
Density
chart.density estimates a smooth distribution; bandwidth controls smoothing and color compares groups.
Box
chart.box summarizes the center and spread of a numeric distribution, optionally split into categories.
Grids and pies
Heatmap
chart.heatmap places cells on two categorical axes and uses a numeric color channel for intensity.
Pie
chart.pie shows a small part-to-whole comparison. Use it when there are only a few categories and their proportions are the point.
Ranges, references, and layers
Band
chart.band fills the range between y1 and y2, commonly for uncertainty or a forecast interval.
Rule
chart.rule draws a reference line at an x or y value: a number, a column, or any expression, such as a named threshold.
Caption
caption adds explanatory text below a chart. In a composed chart, write it as a parenthesized option.
Compose
chart.compose layers compatible marks over shared axes. Inside its indented body, write each chart and put chart-wide options in parentheses.
The indented body is required because a line aligned with the opening expression begins a new document block. Short compositions can stay inline:
Options
Options change presentation without changing the data. Previous sections have shown many, and here is the list:
• title and caption explain the chart.
• width and height set its preferred size.
• legend = false hides the legend.
• x-label and y-label override axis labels.
• x-min, x-max, y-min, and y-max set numeric domains.
• Axis ticks and tooltips inherit the formats attached to their table columns.
• stack, orient, bins, bandwidth, and opacity tune particular chart types.
Where next
• doc/ui.ki — arrange charts, controls, and text into a page