Menu Close Log in Get started

Learn Metabase

Guide to line charts

Line charts are good for plotting data captured in a sequence, whether that sequence is the passage of time, or steps in a process or flow.

These charts are typically used to plot a time series (also known as a run chart): a set of markers connected by lines, with the x axis showing the passage of time and the y axis plotting the value of a metric at each moment.

How to create a line chart

Let’s take a look at the orders table in the Sample Dataset that ships with Metabase. From the main navigation bar, click on Ask a question -> select Simple question -> Pick the Sample Dataset -> and select the Orders table. You should get a table that looks like figure 1. Click on Visualization in the bottom right to bring up the visualization sidebar.

<em>Fig. 1</em>. The orders table's records displayed using the default table visualization. The left sidebar shows available visualization types for the results.
Fig. 1. The orders table's records displayed using the default table visualization. The left sidebar shows available visualization types for the results.

Let’s start with how not to create a line chart. If you select the Line visualization, Metabase will present you with an empty line chart.

<em>Fig. 2</em>. An empty line chart, before setting the x and y axes.
Fig. 2. An empty line chart, before setting the x and y axes.

Metabase can’t read minds (yet), so it doesn’t know which columns from the orders table to use for the x and y axes. To create a line chart, you’ll need to pick a metric for Metabase to plot over time. For example, you could show order totals over time by setting the x axis to created_at and the y axis to total. Metabase will automatically plot the line chart:

<em>Fig. 3</em>. A noisy line chart after setting the x and y axes, without first summarizing the data.
Fig. 3. A noisy line chart after setting the x and y axes, without first summarizing the data.

That’s technically a line chart, but it looks more like the cardiograph of a startled hummingbird, and that’s even after Metabase has truncated the results shown. (If you hover over the gray warning triangle in the upper right, you’ll see that Metabase has only plotted 2,000 rows.)

To make the chart more legible, we can summarize the data, so each point on the line chart is an aggregate of rows — “buckets” of records. (It’s much more common to plot unaggregated rows in visualizations like pin maps, or a scatterplot, e.g., to show each product plotted by price and rating.)

As an example of an aggregated metric, let’s plot the sum of order totals for each month. Click on the green Summarize button to pull up the summarize sidebar. Metabase defaults to counting the records, but we’re not interested in the number of orders, so we’ll click on Count and change it to Sum of and select Total under Order.

Next, we’ll want to group our order totals by month. In the Group by section, under Order, mouse over the Created At field click on the + button to add the grouping.

<em>Fig. 5</em>. Hover over <strong>Created At</strong> and click on the plus button to add a grouping by month. You can select other time intervals (day, week, year) by clicking on <strong>by month</strong>.
Fig. 5. Hover over Created At and click on the plus button to add a grouping by month. You can select other time intervals (day, week, year) by clicking on by month.

As soon as you add the grouping, Metabase updates the chart:

<em>Fig. 6</em>. The sum of order totals by month.
Fig. 6. The sum of order totals by month.

This chart is a lot easier to read. And, of course, we can always select a section of the line to filter the results for that time period, and drill through to see those individual, unaggregated records.

<em>Fig. 7</em>. Zooming in and drilling through a line chart to view individual records.
Fig. 7. Zooming in and drilling through a line chart to view individual records.

Customizing your line chart

There are too many settings to cover here without boring you, so we’ll just give you some highlights.

Display tab

The Display tab lets you change the line color and style, handle missing values, and so on. If you plan on embedding your chart in your app, check out our white labeling option for even more customization.

Trend lines and goal lines

For time series, toggle the Trend line option and Metabase will auto-calculate a trend line. You can also add a Goal line by specifying a value and a label.

<em>Fig. 8</em>. Line chart with goal and trend lines.
Fig. 8. Line chart with goal and trend lines.

Goal lines are especially useful when paired with Alerts. For example, if you’re monitoring sales, and you only want to get notified if a metric dips below a certain threshold, you can add a goal line to specify that threshold and get an email or Slack message when the line goes under it.

Line, area, or bar chart?

We’ve been talking strictly about line charts so far, but bar and area charts are very similar, and there are good reasons to choose them instead of a line chart, depending on what you’re trying to communicate:

<em>Fig. 9</em>. An area chart.
Fig. 9. An area chart.

You can also use combinations of line and area charts to visualize different aggregations, like the count and sum of order totals:

<em>Fig. 10</em>. The count of orders as a blue line, set against the green area chart plotting the sum of order totals.
Fig. 10. The count of orders as a blue line, set against the green area chart plotting the sum of order totals.

You can also use a combo chart for this, which we cover in our documentation.

Axes tab

Here you can adjust the scale of the x and y axes. For the x axis, you can select either time series or ordinal scales. Time series will limit the number of values displayed, whereas the ordinal scale will list each value in the series along the x axis. Use an ordinal scale if you’re plotting steps in a sequence.

For the y axis, you can select linear (the default), or power or log scales. Logarithmic scales are great for showing the rate of change over time, especially when your data has an exponential rise or decay.

<em>Fig. 11</em>. The log scale view of the sum of order totals by month shows us that the growth in totals has flattened out over time.
Fig. 11. The log scale view of the sum of order totals by month shows us that the growth in totals has flattened out over time.

And you can probably just ignore power scales.

Line chart tips

Metabase takes care of a lot of the best practices for visualizing data for you, but here are some tips to keep in mind when creating line charts.

Pair a line chart with a trend chart

When creating a dashboard, you can pair a line chart with a Trend chart to make the latest value easy to read.

<em>Fig. 12</em>. Pair a line chart with a trend chart to show the latest number.
Fig. 12. Pair a line chart with a trend chart to show the latest number.

Hover over a label to highlight a line

You can hover over the name of one of your series in the legend to highlight it and make the others fade out.

<em>Fig. 13</em>. Hovering over labels in the legend hill highlight the corresponding line.
Fig. 13. Hovering over labels in the legend hill highlight the corresponding line.

For time series, filter out any time period still in progress

When dealing with time series, your charts can look nicer if you add a filter to exclude the day, week, or month that’s currently in progress; otherwise your chart will have a huge drop on the far right because of the partial or incomplete time period.

Further reading

Want to get content like this in your inbox?