Skip to content

Commit ed789df

Browse files
committed
Make advanced chart examples editable individually
1 parent d45d52b commit ed789df

11 files changed

Lines changed: 361 additions & 191 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
rows:
3+
- component: chart
4+
title: Revenue
5+
ymin: 0
6+
toolbar: true
7+
- series: Chicago Store
8+
x: 2021
9+
value: 35
10+
- series: Chicago Store
11+
x: 2022
12+
value: 15
13+
- series: Chicago Store
14+
x: 2023
15+
value: 45
16+
- series: New York Store
17+
x: 2021
18+
value: 30
19+
- series: New York Store
20+
x: 2022
21+
value: 55
22+
- series: New York Store
23+
x: 2023
24+
value: 19
25+
---
26+
27+
A line chart with multiple series. One of the most common types of charts, often used to show trends over time.
28+
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.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
rows:
3+
- component: chart
4+
title: Gross domestic product and its growth
5+
type: scatter
6+
xtitle: Growth Rate
7+
ytitle: GDP (Trillions USD)
8+
height: 500
9+
marker: 8
10+
xmin: 0
11+
xmax: 10
12+
ymin: 0
13+
ymax: 25
14+
yticks: 5
15+
- series: Brazil
16+
x: 2.5
17+
y: 2
18+
- series: China
19+
x: 6.5
20+
y: 14
21+
- series: United States
22+
x: 2.3
23+
y: 21
24+
- series: France
25+
x: 1.5
26+
y: 3
27+
- series: South Africa
28+
x: 0.9
29+
y: 0.3
30+
---
31+
32+
A scatter plot with multiple custom options.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
rows:
3+
- component: chart
4+
title: Survey Results
5+
type: heatmap
6+
ytitle: Database managemet system
7+
xtitle: Year
8+
color:
9+
- purple
10+
- purple
11+
- purple
12+
- series: PostgreSQL
13+
x: '2000'
14+
y: 48
15+
- series: SQLite
16+
x: '2000'
17+
y: 44
18+
- series: MySQL
19+
x: '2000'
20+
y: 78
21+
- series: PostgreSQL
22+
x: '2010'
23+
y: 65
24+
- series: SQLite
25+
x: '2010'
26+
y: 62
27+
- series: MySQL
28+
x: '2010'
29+
y: 83
30+
- series: PostgreSQL
31+
x: '2020'
32+
y: 73
33+
- series: SQLite
34+
x: '2020'
35+
y: 38
36+
- series: MySQL
37+
x: '2020'
38+
y: 87
39+
---
40+
41+
## Heatmaps
42+
43+
You can build heatmaps using the `heatmap` top-level property.
44+
45+
The data format follows the [apexcharts heatmap format](https://apexcharts.com/angular-chart-demos/heatmap-charts/basic/),
46+
where each series is represented as a line in the chart:
47+
- The `x` property of each item will be used as the x-axis value.
48+
- The `series` property of each item will be used as the y-axis value.
49+
- The `y` property of each item will be used as the value to display in the heatmap
50+
51+
The `color` property sets the color of each series separately, in order.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
rows:
3+
- component: chart
4+
title: Project Timeline
5+
type: rangeBar
6+
time: true
7+
color:
8+
- teal
9+
- cyan
10+
labels: true
11+
xmin: '2021-12-28'
12+
xmax: '2022-01-04'
13+
- series: Phase 1
14+
label: Operations
15+
value:
16+
- '2021-12-29'
17+
- '2022-01-02'
18+
link: /examples/chart.sql?phase=1
19+
- series: Phase 2
20+
label: Operations
21+
value:
22+
- '2022-01-03'
23+
- '2022-01-04'
24+
- series: Yearly maintenance
25+
label: Maintenance
26+
value:
27+
- '2022-01-01'
28+
- '2022-01-03'
29+
---
30+
31+
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.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
rows:
3+
- component: chart
4+
title: Accounts expiring soon
5+
type: bar
6+
horizontal: true
7+
labels: true
8+
show_legend: false
9+
- label: 30 days
10+
value: 100
11+
color: red
12+
- label: 60 days
13+
value: 200
14+
color: orange
15+
- label: 90 days
16+
value: 300
17+
color: green
18+
---
19+
20+
## Coloring a single value
21+
22+
A data row can carry its own `color`, to paint the one bar, slice or point it
23+
plots. Use it when the color says something the axes do not: a threshold
24+
crossed, a status, the one category the reader should look at first.
25+
26+
```sql
27+
select 'chart' as component, 'bar' as type, true as horizontal,
28+
true as labels, false as show_legend;
29+
select
30+
window_label as label,
31+
accounts as value,
32+
case when days <= 30 then 'red' when days <= 60 then 'orange' else 'green' end as color
33+
from expiring_accounts order by days;
34+
```
35+
36+
A row color takes precedence over the color of its series. On a `line` or an
37+
`area` chart it paints the marker of the point, so set `marker` for it to show.
38+
A `heatmap` shades its cells from their own value and ignores it.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
rows:
3+
- component: chart
4+
title: Support tickets
5+
type: pie
6+
labels: true
7+
- label: Resolved
8+
value: 72
9+
color: green
10+
- label: In progress
11+
value: 21
12+
color: yellow
13+
- label: Overdue
14+
value: 7
15+
color: red
16+
---
17+
18+
A pie chart whose rows choose their own slice colors.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
rows:
3+
- component: chart
4+
title: CPU temperature
5+
type: line
6+
time: true
7+
ytitle: °C
8+
ymax: 100
9+
color: azure
10+
marker: 4
11+
- yline: 70
12+
label: target
13+
color: green
14+
- yline: 90
15+
yline_end: 100
16+
label: throttling
17+
color: red
18+
- x: '2024-05-01T08:00:00Z'
19+
y: 52
20+
- x: '2024-05-01T09:00:00Z'
21+
y: 58
22+
- x: '2024-05-01T10:00:00Z'
23+
y: 71
24+
- x: '2024-05-01T11:00:00Z'
25+
y: 83
26+
- x: '2024-05-01T12:00:00Z'
27+
y: 94
28+
- x: '2024-05-01T13:00:00Z'
29+
y: 76
30+
- x: '2024-05-01T14:00:00Z'
31+
y: 63
32+
---
33+
34+
## Reference lines
35+
36+
A row with a `yline` is not plotted as a data point, but drawn as a line across
37+
the whole chart, at that value of the y axis. Use it for the limit that the data
38+
should be read against: a disk quota, an alarm threshold, a service level
39+
objective. Add `yline_end` to make it a band instead of a line.
40+
41+
Reference lines are rows, so they come from a query like everything else,
42+
and a chart can have as many of them as the query returns:
43+
44+
```sql
45+
select 'chart' as component, 'CPU temperature' as title, true as time, 100 as ymax;
46+
select celsius as yline, name as label, color as color from thresholds;
47+
select measured_at as x, celsius as y from readings order by measured_at;
48+
```
49+
50+
They are drawn as annotations rather than as an extra series, so they are not
51+
added to the total of a `stacked` chart, and are not filled in an `area` chart.
52+
53+
A line outside of the y axis is not drawn, and does not stretch the axis to fit,
54+
so set `ymax` when the limit is above the data.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
rows:
3+
- component: chart
4+
title: Request latency
5+
type: area
6+
time: true
7+
ytitle: ms
8+
color: blue-lt
9+
marker: 3
10+
- xline: '2024-05-01T10:00:00Z'
11+
label: deploy
12+
color: green
13+
- xline: '2024-05-01T11:30:00Z'
14+
xline_end: '2024-05-01T13:00:00Z'
15+
label: incident
16+
color: red
17+
- x: '2024-05-01T08:00:00Z'
18+
y: 120
19+
- x: '2024-05-01T09:00:00Z'
20+
y: 134
21+
- x: '2024-05-01T10:00:00Z'
22+
y: 128
23+
- x: '2024-05-01T11:00:00Z'
24+
y: 141
25+
- x: '2024-05-01T12:00:00Z'
26+
y: 512
27+
- x: '2024-05-01T13:00:00Z'
28+
y: 470
29+
- x: '2024-05-01T14:00:00Z'
30+
y: 156
31+
- x: '2024-05-01T15:00:00Z'
32+
y: 133
33+
---
34+
35+
## Marking events
36+
37+
`xline` is the counterpart of `yline`: it marks a position on the x axis instead
38+
of a value on the y axis. On its own it marks a moment, like a deployment.
39+
With `xline_end`, it covers everything in between, like an incident or a
40+
maintenance window. A single query can draw a whole log of them:
41+
42+
```sql
43+
select started_at as xline, ended_at as xline_end, summary as label,
44+
case severity when 'outage' then 'red' else 'orange' end as color
45+
from incidents where started_at > $since;
46+
```
47+
48+
When `time` is set, an `xline` is a date or a timestamp, written like the `x` of
49+
a data point. On a chart with text labels on the x axis, it is one of those labels.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
rows:
3+
- component: chart
4+
title: Disk usage
5+
type: bar
6+
horizontal: true
7+
ymax: 100
8+
color: azure
9+
labels: true
10+
- yline: 90
11+
label: full
12+
color: red
13+
- xline: db-1
14+
label: watched
15+
color: purple
16+
- x: backup-1
17+
y: 41
18+
- x: web-2
19+
y: 63
20+
- x: db-1
21+
y: 88
22+
- x: web-1
23+
y: 96
24+
---
25+
26+
## Reference lines follow their axis
27+
28+
A reference belongs to the column it is written in, not to a direction on the
29+
screen. `yline` always marks a value of `y`, and `xline` a position on `x`,
30+
whichever way round the chart is drawn. A `horizontal` bar chart runs its y axis
31+
from left to right, so a `yline` is drawn down the chart and an `xline` picks out
32+
one of the bars.
33+
34+
```sql
35+
select 'chart' as component, 'bar' as type, true as horizontal, 100 as ymax;
36+
select 90 as yline, 'full' as label, 'red' as color;
37+
select 'db-1' as xline, 'watched' as label, 'purple' as color;
38+
select host as x, percent_used as y from disks order by percent_used;
39+
```
40+
41+
A `pie` has no axes and ignores reference lines, and on a `heatmap`, whose y axis
42+
holds the names of the series, only `xline` has a meaning.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
rows:
3+
- component: card
4+
title: A dashboard with multiple graphs on the same line
5+
columns: 2
6+
- embed: /examples/chart.sql?color=green&n=42&_sqlpage_embed
7+
- embed: /examples/chart.sql?_sqlpage_embed
8+
---
9+
10+
## Multiple charts on the same line
11+
12+
You can create information-dense dashboards by using the [card component](?component=card#component)
13+
to put multiple charts on the same line.
14+
15+
For this, create one sql file per visualization you want to show,
16+
and set the `embed` attribute of the [card](?component=card#component) component
17+
to the path of the file you want to include, followed by `?_sqlpage_embed`.

0 commit comments

Comments
 (0)