Choosing the right chart: bar, line, scatter, histogram
A chart is not decoration. It shows a shape a table hides. The kind of column decides the kind of chart.
Four questions, four charts
Comparing categories is a bar chart; change over time is a line; the relationship between two numbers is a scatter; the spread of one number is a histogram. Those four cover most questions.
QueryDeck suggests one from the result's column types: a date-like first column with numbers becomes a line, a category with a number becomes a bar, two numbers become a scatter, a single number becomes a histogram.
| Question | Chart | Example |
|---|---|---|
| Which category is largest? | bar | revenue by channel |
| How did it change? | line | sessions per day |
| Are they related? | scatter | duration versus conversion |
| How is it spread? | histogram | order value distribution |
| What is the mix? | stacked bar or table | share by plan |
Do not crop the axis
Starting a bar chart's y-axis above zero makes a small difference look enormous. A bar encodes value as length, so it must start at zero. A line may start higher, but the axis has to say so.
Sorting matters too. Ordering category bars by value shows the ranking; ordering by name helps lookup but hides comparison.
Colour and series
Use colour only when it carries meaning. One series needs one colour; several series are clearer with direct labels than with a legend the eye must chase. Colour alone also fails for readers with colour vision deficiency.
Beyond about six series a line chart stops being readable. Keep the largest few, group the rest, or split into small multiples.
Keep the table beside the chart
The chart gives shape; the table gives values. QueryDeck draws the chart directly under the result table so both readings are available, labels the chart with a summary for screen readers, and leaves exact values to the table.
Shape the query before the chart
Decide the shape of the result first. A category total is GROUP BY on one column, a time series groups by a date, a scatter keeps two numeric columns, and a histogram keeps one. If you started from SELECT *, the first step is dropping the columns the chart does not need.
-- bar: totals per category
SELECT channel, SUM(revenue) AS revenue FROM orders GROUP BY channel;
-- line: daily trend
SELECT session_date, COUNT(*) AS sessions FROM sessions GROUP BY session_date;
-- scatter: two numbers
SELECT quantity, revenue FROM orders WHERE revenue IS NOT NULL;
-- histogram: one number
SELECT revenue FROM orders;
Read the chart with the table
The chart owns the trend and the table owns the values. When a bar looks out of line, find that row in the table beside it and read the exact number. Because QueryDeck draws the chart under the result table, both views describe the same result set.
A chart published without its table cannot be checked later. Export the result as CSV alongside the image so the shape and the values are kept from the same moment, and note the axis unit and sort order in the caption.
Questions
When is a pie chart acceptable?
For a share split with two or three items. With more, angles are hard to compare and a bar chart is better.
When should a log axis be used?
When values span hundreds of times. It cannot represent zero or negative values.
Sources
Every query in this guide runs against the built-in sample data.
Open the lab