Sub topic 12
Adding trendlines and error bars
This chapter assumes you can insert a chart, open the chart editor, and select a series in the Customize tab. It also assumes you know what a scatter chart is. You will add trendlines to show direction in noisy data and error bars to show uncertainty around values. You will also learn how to check what the chart computes.
What each feature does
A trendline is a fitted line or curve that summarises the overall pattern in a series. It is calculated from the series values, and it does not replace them.
Error bars are short whiskers drawn at each data point. They show how far the true value might be above or below the plotted value.
| Feature | Question it answers | Typical data |
|---|---|---|
| Trendline | Which way is this going, and how fast? | Monthly sales, sensor readings, scatter pairs |
| Error bars | How reliable is each value? | Survey averages, repeated measurements, forecasts |
Both live under Customize > Series. Select the series you want first. Each feature belongs to one series, or to all series if you choose "Apply to: All series".
Adding a trendline
Suppose A1:B13 holds a header row plus twelve months of sales. Insert a chart from that range, then follow these steps:
- In the chart editor, open Customize and expand Series.
- Under Apply to, pick the series.
- Tick Trendline.
- Choose a Type.
- Set Label to Use Equation if you want the fitted formula printed on the chart.
- Tick Show R² if you want the fit statistic.
Sheets draws the trendline in the series colour. You can change its colour, opacity, thickness, and dash style in the same section.
Trendline types
| Type | Shape | Use when |
|---|---|---|
| Linear | Straight line | Steady growth or decline |
| Exponential | Curve that grows or shrinks by a constant percentage | Compounding growth, decay |
| Polynomial | Curve with bends (you choose the degree) | Rise then fall, or a single hump |
| Logarithmic | Fast change that levels off | Diminishing returns |
| Power series | Curve of the form y = a·xᵇ | Scaling relationships |
| Moving average | Smoothed line over a window of points | Removing short-term noise |
Exponential, logarithmic, and power fits have restrictions. An exponential or power fit needs positive y values. A logarithmic or power fit needs positive x values. If your data has zeros or negatives, those types may be unavailable or may not draw.
Polynomial degree controls flexibility. Degree 2 gives one bend. Higher degrees follow the data more closely but can swing wildly between points and extrapolate badly. A moving average has no equation. It has a period, which is the number of points averaged at each position.
Reading the equation and R²
The equation label shows the fitted formula, for example y = 412.3x + 8120. In a linear fit, the number before x is the slope. It is the average change in y for each one-unit step in x.
R² runs from 0 to 1. A value near 1 means the curve follows the data closely. A value near 0 means the fit explains little. A high R² does not prove that x causes y, and it does not make a forecast safe.
For a line chart with text or date labels on the horizontal axis, Sheets treats the points as numbered positions. The "x" in the equation is then a position count (1, 2, 3, …) or a date serial number, not the label you see. This surprises people when they try to reuse the equation. For a scatter chart, x is the actual numeric value of your x column.
Checking the trendline with formulas
You can reproduce the chart's linear fit in cells. This is useful when you need the numbers in a report or want to confirm what the chart shows.
=SLOPE(B2:B13, A2:A13)
=INTERCEPT(B2:B13, A2:A13)
=RSQ(B2:B13, A2:A13)
=FORECAST(13, B2:B13, A2:A13)In these formulas, A2:A13 holds the x values (for example 1 to 12), and B2:B13 holds the y values. SLOPE and INTERCEPT give the line's coefficients, RSQ gives R², and FORECAST predicts y at x = 13. If your x column holds dates, the values are serial numbers, and the slope is per day.
Adding error bars
Error bars use the same area of the editor. Select a series, then tick Error bars. You then choose how the bar length is computed.
| Type | Bar length | Typical use |
|---|---|---|
| Constant | The same fixed amount for every point, such as ±5 | A known measurement tolerance |
| Percent | A percentage of each point's own value, such as ±10% | Uncertainty that scales with size |
| Standard deviation | A multiple of the standard deviation of the series | Showing spread across the series |
Enter the amount in the Value field. For standard deviation, the value is the multiplier, so 1 draws bars one standard deviation long.
Two limits are worth knowing:
- The standard deviation option uses the spread of the whole plotted series. It is not a per-point value taken from another column.
- Constant and percent bars are the same for every point in the type's rule. Sheets does not read a separate "error" column in the chart editor.
If each point has its own margin of error, the chart editor cannot draw it directly. A common workaround is to add two helper series, an upper bound and a lower bound, computed with formulas. Plot them as thin lines or as a shaded band using an area series in a combo chart.
=B2 + C2
=B2 - C2In these formulas, column B holds the value and column C holds that row's margin of error. Fill the first formula down a new "Upper" column and the second down a new "Lower" column. Then add both columns as series.
Combining a trendline and error bars
You can use both on the same series. The trendline shows the direction and the error bars show how uncertain each point is. If the bars are long enough to overlap the trendline everywhere, the trend may be weaker than it looks.
Common mistakes
- Wrong series selected. In a chart with several series, settings apply to whichever series appears under Apply to. Check it before you tick the box.
- Trendline on too few points. A fit through four or five points can look convincing and still mean little. Treat it as a description, not a prediction.
- Extrapolating without a reason. Sheets can extend a trendline forward only within the chart's axis range, but a line drawn past your data suggests a forecast. Say so in the title or a note if you do it.
- Misreading the equation on a date axis. As noted above, x may be a date serial number. Compute the fit in cells if you need numbers you can explain.
- Using error bars to mean something else. State in a note or the chart title what the bars represent, for example "Bars show ±1 standard deviation". Readers cannot tell from the chart alone.
- Overloading the chart. Several series, each with a trendline, equation label, and error bars, becomes unreadable. Apply the features to the one or two series that carry your message.
Exercise
A line chart shows twelve monthly sales figures in B2:B13, with the months as text labels in A2:A13. You add a linear trendline with the equation label and read y = 150x + 2000. A colleague asks what sales to expect in month 14. What do you calculate, and what caution would you give?
Show answer
Month 14 is the 14th position, so y = 150 × 14 + 2000 = 4100. This works because, with text labels, x is the point's position (1 to 12). You can confirm it with =FORECAST(14, B2:B13, {1;2;3;4;5;6;7;8;9;10;11;12}). The caution is that this extrapolates beyond the data. Check R², and remember that a straight line may not hold, for example if sales are seasonal.
Exercise
Each measurement in C2:C11 has its own margin of error in D2:D11. The Error bars option offers only constant, percent, and standard deviation. How can you show each point's own margin on the chart?
Show answer
Add two helper columns, Upper (=C2+D2) and Lower (=C2-D2), and fill them down. Add them as extra series in the chart, for example as thin lines or an area band in a combo chart. The chart editor's error bars cannot read a separate error column.