Charts, KPIs and dashboards from a notebook

17 chart kinds plus KPI tiles, which charts take clicks, status withheld on partial data, dashboards, and notebooks that read like reports.

By

Somebody asks for "the numbers" every Monday. You have the queries. What you don't have is a picture of them that you'd put in front of anyone, so you paste a grid into a slide and apologize for it.

SQLly's results grid has had charts and pivots for a while, and I've written about why they live in the grid. Notebooks add chart, table, pivot and KPI cells on top of that, and a dashboard cell that lays them out on a page. Here's what they do and where they stop. (Fifth in the notebooks series.)

A chart cell under a query offers the charts that fit its columns, KPI tiles compare against the previous period and a target, and clicking a bar filters the cells that read the chart.

Real recording · typing sped up · Northwind demo data

A chart picked from the chart cell's suggestions, the KPI scorecard, and a click on a bar filtering the KPIs that follow it. Recorded in the app. Watch the whole recording, with chapters.

Chart cells read a result, they don't run a query

Add a Chart cell under a query, pick that query as its input, and it suggests three charts worked out from the result's columns, such as "Suggested: Bar of Revenue by ShipCountry". Pick one or press Edit and build it yourself. The chart redraws whenever its input runs. It never queries the database on its own.

There are 17 chart kinds: bar, line, area, scatter, bubble, histogram, pie, donut, heatmap, calendar heatmap, waterfall, funnel, treemap, box plot, cohort retention, correlation matrix and sparkline. A headline number with its change is a KPI cell rather than a chart. The editor covers the usual things, plus a few that matter more in a notebook: Top N with "Group the rest as Other", date grouping from hour to year, reference lines written as 100 Target; 80 Warning?; 50 Critical!, annotations on dates or categories, and an expected range that shades a rolling average of the last 7 points plus or minus three standard deviations and marks what falls outside.

The suggestions follow rules you can see in the docs. ID-like columns are never treated as measures. Pie and donut are only suggested for two to six non-negative slices with no time axis. And when the input is sampled or cut short, the suggestions say so.

A chart cell under a revenue-by-country query before a chart is chosen, with a strip of three suggested charts worked out from the result's columns
A new chart cell suggests three charts from its input's columns.

Two renderers, and you can tell which one you got

Bar, line, area, scatter, histogram, pie and donut are drawn live by the results grid's chart engine. Everything else, and any of those seven using a setting the live engine doesn't have, like reference lines, stacked bars or an expected range, is drawn by the report renderer. That's the same SVG renderer every export uses, so a chart in the cell is drawn the same way in the exports. Charts use a color-blind-safe palette in light and dark.

The catch is that not every chart can be clicked. I'll get to which ones in the click-to-filter section.

Three chart cells drawn by the report renderer: a heatmap of revenue by category and country, a quarter-over-quarter waterfall and a customer loyalty funnel
A heatmap, a waterfall and a funnel, drawn by the same renderer the exports use.

KPI tiles won't give you a status they can't back up

A KPI cell is a row of up to eight tiles. Each takes an aggregate of a column, compares it with the previous period, another cell's result or a fixed target, and says whether higher or lower is better. Warning and critical thresholds turn that into On track, Warning or Critical, with a sparkline when there's a date column.

If the input was cut short or sampled, the tile still shows its number but withholds the status: "Status withheld: the input is incomplete". A green "On track" computed from the first 100,000 rows of a 2.4 million row result is worse than no status at all.

That snapshot limit applies to every cell that reads another cell's rows. Charts, tables, pivots and KPIs work from a snapshot of up to 100,000 rows, and when the result is bigger a badge says how much they cover, like "First 100,000 of 2,400,000 rows", with "Totals, charts and KPIs here cover only these rows, not the whole result."

A row of KPI tiles showing revenue and orders against the previous month with sparklines and status labels, and customers against a target, above a formula cell and a Markdown cell that uses its value
KPI tiles against the previous month and a target, each with its status.

Click a bar to filter the cells that follow it

On a table, chart, pivot or KPI cell, press Follow a chart and pick a chart. Click a bar in that chart and the following cells show only that category, with a chip like "Filtered by by_category: CategoryName = Beverages". It filters the rows already downloaded, "Local filter on downloaded rows; nothing is re-run.", so it's instant and never sends a query.

Which charts take clicks depends on who drew them. Drawn by the report renderer, bar, line, area, pie, donut, funnel, treemap and waterfall charts know where each mark is, so a click finds its category directly. Drawn live, bar, line, area, scatter, pie and donut charts take clicks. Histograms, heatmaps, calendar heatmaps, cohort grids, correlation matrices, box plots, sparklines, and scatter or bubble charts drawn by the report renderer don't.

Full disclosure on the live ones. They come from the results grid's library, which is mine and lives in its own repo, and it keeps its hit testing private. So the notebook works out where each bar is from the same layout rules the chart uses. It matches in my tests, but it's a copy of layout math that lives somewhere else, and the proper fix is a public hit test in that library, which needs a release of it.

A category bar chart with its tallest bar clicked, and the KPI tiles and table below it showing only that category, with a filter chip and a note that only downloaded rows are filtered
Clicking a bar filters the cells that follow the chart, on rows already downloaded.

A dashboard is just another cell

Press Dashboard in the top bar and you get a 12-column canvas. Add tiles from any cell with a result: SQL results show as grids, charts and KPIs as themselves, Markdown rendered. Drag edges to resize, from one to eight rows of 110 pixels high. Split it into sections and tabs, give a tile a condition for when it's shown, or a drill-through that opens another section or tab, optionally setting a parameter from the value you picked. Under 720 pixels wide it switches to a narrow layout.

Because the dashboard is a cell, it's saved in the same file, shows up in diffs, and always shows the notebook's own results. View shows it without any SQL, editors or settings. Present shows it full screen, one section per slide or the whole thing, with arrow keys, Space and Page Down to move.

Two rules keep it from becoming a liability. The filter bar never starts a query by itself. Once you apply a value it tells you what refreshing costs, "Refreshing runs 3 queries on Storefront Prod.", and waits for Refresh. And a notebook with any cell allowed to change data can't be viewed or presented at all. It names the cells and tells you to make them read-only first.

A sales dashboard in viewer mode with a row of KPI tiles, a revenue-by-country chart beside a top-customers table, and a note tile, with no SQL or editors visible
The dashboard viewer shows results, filters and drill-throughs, never the SQL.

Or skip the dashboard and let the notebook read like a report

Sometimes a dashboard is more than you need. You want the notebook itself, top to bottom, just without the SQL in the way. So any cell can now show only its output: a query shows its result grid, a pivot shows the pivot table, a chart shows the chart. No header, editor or result tabs. The output is sized to fit and sits flush with the cells around it. Press E in command mode or choose Embed output from the cell menu, or turn on Embed All Outputs in the More menu, which new cells follow too.

Hover an output and a small control lets you show it in full again, run it or open its menu, and a grid, pivot or chart can be resized by dragging its bottom edge. A cell that hasn't run shows a Run button, a failure stays visible, and an out-of-date, partial or running result keeps a small mark in the corner, so a report-style notebook doesn't hide stale numbers any better than the full one. Pivots and charts start with their settings hidden, and Show configuration puts the field list or the chart options back beside the output. Double-click a value in an embedded pivot and it switches to the rows behind it, with Back to pivot.

There's a related switch for people reading your notebook. Lock view pins a query's results grid to its rows, pivot or chart, so whoever opens it sees the view you chose and can't switch away. Clicking a pivot value or a chart bar in a locked grid lists the rows behind it underneath. Both of these needed a release of that same grid library, 11.2, so a query's grid can drop its tab bar and side panels completely instead of folding them into a thin strip.

A notebook with every output embedded: a Markdown heading, a category summary grid, a pivot of revenue by category and country without its field list, and a bar chart by country, all flush with no cell headers or editors
Embed All Outputs: the same notebook, read as a report. The query behind the pivot stays collapsed in full.

The rough edges

A forced light or dark presentation theme switches the whole app's theme while you present, then switches it back when you stop or close the tab, because the palette is global. A new KPI cell shows one tile over the first numeric column until you edit it. In the browser build, a chart's Export PNG needs the desktop app. And embedded outputs have three gaps: only the active result set of a cell with several statements is embedded, a pivot or chart panel you'd collapsed comes back expanded after you leave embedded mode, and a drill in a locked grid whose result spilled to disk filters the grid itself, which you only see after unlocking it.

The details are on Charts, tables, pivots and KPIs, Dashboards and presentation and Embedded outputs and report-style notebooks. The next post is about checking the numbers. If a suggested chart is ever obviously wrong for your data, send me the column types.