Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
rows:
- component: chart
title: Revenue
ymin: 0
toolbar: true
- series: Chicago Store
x: 2021
value: 35
- series: Chicago Store
x: 2022
value: 15
- series: Chicago Store
x: 2023
value: 45
- series: New York Store
x: 2021
value: 30
- series: New York Store
x: 2022
value: 55
- series: New York Store
x: 2023
value: 19
---

A line chart with multiple series. One of the most common types of charts, often used to show trends over time.
Also demonstrates the use of the `toolbar` attribute to allow the user to download the graph as an image or the data as a CSV file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
rows:
- component: chart
title: Gross domestic product and its growth
type: scatter
xtitle: Growth Rate
ytitle: GDP (Trillions USD)
height: 500
marker: 8
xmin: 0
xmax: 10
ymin: 0
ymax: 25
yticks: 5
- series: Brazil
x: 2.5
y: 2
- series: China
x: 6.5
y: 14
- series: United States
x: 2.3
y: 21
- series: France
x: 1.5
y: 3
- series: South Africa
x: 0.9
y: 0.3
---

A scatter plot with multiple custom options.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
rows:
- component: chart
title: Survey Results
type: heatmap
ytitle: Database management system
xtitle: Year
color:
- purple
- purple
- purple
- series: PostgreSQL
x: '2000'
y: 48
- series: SQLite
x: '2000'
y: 44
- series: MySQL
x: '2000'
y: 78
- series: PostgreSQL
x: '2010'
y: 65
- series: SQLite
x: '2010'
y: 62
- series: MySQL
x: '2010'
y: 83
- series: PostgreSQL
x: '2020'
y: 73
- series: SQLite
x: '2020'
y: 38
- series: MySQL
x: '2020'
y: 87
---

## Heatmaps

Set `type` to `heatmap` on the chart row.

The data format follows the [apexcharts heatmap format](https://apexcharts.com/angular-chart-demos/heatmap-charts/basic/),
where each series is represented as a line in the chart:
- The `x` property of each item will be used as the x-axis value.
- The `series` property of each item will be used as the y-axis value.
- The `y` property of each item will be used as the value to display in the heatmap

The `color` property sets the color of each series separately, in order.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
rows:
- component: chart
title: Project Timeline
type: rangeBar
time: true
color:
- teal
- cyan
labels: true
xmin: '2021-12-28'
xmax: '2022-01-04'
- series: Phase 1
label: Operations
value:
- '2021-12-29'
- '2022-01-02'
link: /examples/chart.sql?phase=1
- series: Phase 2
label: Operations
value:
- '2022-01-03'
- '2022-01-04'
- series: Yearly maintenance
label: Maintenance
value:
- '2022-01-01'
- '2022-01-03'
---

A timeline displaying events with a start and an end date. A data row can include a `link` to open when its bar or tooltip title is clicked.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
rows:
- component: chart
title: Accounts expiring soon
type: bar
horizontal: true
labels: true
show_legend: false
- label: 30 days
value: 100
color: red
- label: 60 days
value: 200
color: orange
- label: 90 days
value: 300
color: green
---

## Coloring a single value

A data row can carry its own `color`, to paint the one bar, slice or point it
plots. Use it when the color says something the axes do not: a threshold
crossed, a status, the one category the reader should look at first.

```sql
select 'chart' as component, 'bar' as type, true as horizontal,
true as labels, false as show_legend;
select
window_label as label,
accounts as value,
case when days <= 30 then 'red' when days <= 60 then 'orange' else 'green' end as color
from expiring_accounts order by days;
```

A row color takes precedence over the color of its series. On a `line` or an
`area` chart it paints the marker of the point, so set `marker` for it to show.
A `heatmap` shades its cells from their own value and ignores it.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
rows:
- component: chart
title: Support tickets
type: pie
labels: true
- label: Resolved
value: 72
color: green
- label: In progress
value: 21
color: yellow
- label: Overdue
value: 7
color: red
---

A pie chart whose rows choose their own slice colors.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
rows:
- component: chart
title: CPU temperature
type: line
time: true
ytitle: °C
ymax: 100
color: azure
marker: 4
- yline: 70
label: target
color: green
- yline: 90
yline_end: 100
label: throttling
color: red
- x: '2024-05-01T08:00:00Z'
y: 52
- x: '2024-05-01T09:00:00Z'
y: 58
- x: '2024-05-01T10:00:00Z'
y: 71
- x: '2024-05-01T11:00:00Z'
y: 83
- x: '2024-05-01T12:00:00Z'
y: 94
- x: '2024-05-01T13:00:00Z'
y: 76
- x: '2024-05-01T14:00:00Z'
y: 63
---

## Reference lines

A row with a `yline` is not plotted as a data point, but drawn as a line across
the whole chart, at that value of the y axis. Use it for the limit that the data
should be read against: a disk quota, an alarm threshold, a service level
objective. Add `yline_end` to make it a band instead of a line.

Reference lines are rows, so they come from a query like everything else,
and a chart can have as many of them as the query returns:

```sql
select 'chart' as component, 'CPU temperature' as title, true as time, 100 as ymax;
select celsius as yline, name as label, color as color from thresholds;
select measured_at as x, celsius as y from readings order by measured_at;
```

They are drawn as annotations rather than as an extra series, so they are not
added to the total of a `stacked` chart, and are not filled in an `area` chart.

A line outside of the y axis is not drawn, and does not stretch the axis to fit,
so set `ymax` when the limit is above the data.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
rows:
- component: chart
title: Request latency
type: area
time: true
ytitle: ms
color: blue-lt
marker: 3
- xline: '2024-05-01T10:00:00Z'
label: deploy
color: green
- xline: '2024-05-01T11:30:00Z'
xline_end: '2024-05-01T13:00:00Z'
label: incident
color: red
- x: '2024-05-01T08:00:00Z'
y: 120
- x: '2024-05-01T09:00:00Z'
y: 134
- x: '2024-05-01T10:00:00Z'
y: 128
- x: '2024-05-01T11:00:00Z'
y: 141
- x: '2024-05-01T12:00:00Z'
y: 512
- x: '2024-05-01T13:00:00Z'
y: 470
- x: '2024-05-01T14:00:00Z'
y: 156
- x: '2024-05-01T15:00:00Z'
y: 133
---

## Marking events

`xline` is the counterpart of `yline`: it marks a position on the x axis instead
of a value on the y axis. On its own it marks a moment, like a deployment.
With `xline_end`, it covers everything in between, like an incident or a
maintenance window. A single query can draw a whole log of them:

```sql
select started_at as xline, ended_at as xline_end, summary as label,
case severity when 'outage' then 'red' else 'orange' end as color
from incidents where started_at > $since;
```

When `time` is set, an `xline` is a date or a timestamp, written like the `x` of
a data point. On a chart with text labels on the x axis, it is one of those labels.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
rows:
- component: chart
title: Disk usage
type: bar
horizontal: true
ymax: 100
color: azure
labels: true
- yline: 90
label: full
color: red
- xline: db-1
label: watched
color: purple
- x: backup-1
y: 41
- x: web-2
y: 63
- x: db-1
y: 88
- x: web-1
y: 96
---

## Reference lines follow their axis

A reference belongs to the column it is written in, not to a direction on the
screen. `yline` always marks a value of `y`, and `xline` a position on `x`,
whichever way round the chart is drawn. A `horizontal` bar chart runs its y axis
from left to right, so a `yline` is drawn down the chart and an `xline` picks out
one of the bars.

```sql
select 'chart' as component, 'bar' as type, true as horizontal, 100 as ymax;
select 90 as yline, 'full' as label, 'red' as color;
select 'db-1' as xline, 'watched' as label, 'purple' as color;
select host as x, percent_used as y from disks order by percent_used;
```

A `pie` has no axes and ignores reference lines, and on a `heatmap`, whose y axis
holds the names of the series, only `xline` has a meaning.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
rows:
- component: card
title: A dashboard with multiple graphs on the same line
columns: 2
- embed: /examples/chart.sql?color=green&n=42&_sqlpage_embed
- embed: /examples/chart.sql?_sqlpage_embed
---

## Multiple charts on the same line

You can create information-dense dashboards by using the [card component](?component=card#component)
to put multiple charts on the same line.

For this, create one sql file per visualization you want to show,
and set the `embed` attribute of the [card](?component=card#component) component
to the path of the file you want to include, followed by `?_sqlpage_embed`.
Loading
Loading