Baselines

Horizontal marks added to charts to mark major comparative values of a series like the average, median, min or max.

ChartSQL introduces baseline marks/lines to add context and reference points to chart visualizations. These lines represent significant values such as the average, min, max, median of a series. Baselines provide visual cues for comparison against a common or target value.

See Baselines examples and the @baselines and @baseline-types directives.

-- @chart: column
-- @title: Baselines - Average Baseline
-- @subtitle: An example column chart showing sales by month
-- @formats: currency
-- @series: Sales
-- @baselines: Sales
SELECT 
	TRUNC(date_closed, 'MONTH') as Month,
	sum(amount) as Sales
FROM sales
GROUP BY TRUNC(date_closed, 'MONTH')
ORDER BY TRUNC(date_closed, 'MONTH') ASC

Baseline Directives Overview

  • @baselines: Specifies the series to which baselines are applied and indicates the presence of baseline lines in the chart.

  • @baseline-types (optional): Sets the type of baselines on the specified series. If omitted, the default type, 'average', is applied. Supported types include: 'average', 'min', 'max', or 'median'

Examples

A column chart showcasing average sales with a baseline for the average value:

-- @chart: column
-- @title: Baselines - Average Baseline
-- @subtitle: An example column chart showing sales by month
-- @formats: currency
-- @series: Sales
-- @baselines: Sales
SELECT 
	TRUNC(date_closed, 'MONTH') as Month,
	sum(amount) as Sales
FROM sales
GROUP BY TRUNC(date_closed, 'MONTH')
ORDER BY TRUNC(date_closed, 'MONTH') ASC

A chart with multiple baselines with specified types:

-- @chart: column
-- @title: Baselines - Multiple Baseline Types on one Series
-- @subtitle: An example column chart showing sales by month
-- @formats: currency
-- @series: Sales
-- @baselines: Sales, Sales, Sales
-- @baseline-types: average, min, max
SELECT 
	TRUNC(date_closed, 'MONTH') as Month,
	sum(amount) as Sales
FROM sales
GROUP BY TRUNC(date_closed, 'MONTH')
ORDER BY TRUNC(date_closed, 'MONTH') ASC

Default Behavior

Without specifying types or labels, baselines default to drawing an 'average' line across the specified series in the chart.

Last updated

Support

DiscordX

ChartSQL