Charts
Kvery can render your query results as a chart instead of a table. Charts are a fast way to spot trends and compare values, and they work on dashboards just as well as in the editor.
Available chart types
| Chart | Page | Good for |
|---|---|---|
| Vertical bar | Bar charts | Comparing values across categories |
| Horizontal bar | Bar charts | Category labels that are long |
| Line | Line chart | Trends over time |
| Mixed (bar + line) | Mixed chart | A total plus a rate on one chart |
| Pie | Pie & doughnut | Share of a whole |
| Doughnut | Pie & doughnut | Share of a whole, with a centre |
How a chart is built from your rows
A chart needs two things from your result set:
- Labels — usually the first column (the category or the time axis).
- One or more series — the numeric columns that supply the values.
So a query like:
SELECT month, revenue, orders
FROM monthly_sales
ORDER BY month;
gives you month as the labels and revenue / orders as two series you can
plot. Keep the label column first and your numeric columns after it, and the
chart maps cleanly.
Switching to a chart
Run the query, then choose Chart in the result area and pick the chart type. The chart is drawn from the rows already returned — switching views never re-runs the query.
Tips for good charts
- Aggregate in SQL. Chart a handful of grouped rows (
GROUP BY), not thousands of raw rows — it is faster and far easier to read. - Order the labels with
ORDER BYso a time axis reads left-to-right. - Hide helper columns you don't want plotted with
::hidden. - Name your columns with
AS— the aliases become the series and axis labels.