Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Add Linear Regression to Excel Chart

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To add a linear regression line to an Excel chart, first create a scatter chart from your two-column data, then right-click any data point and choose Add Trendline. In the Format Trendline pane, select Linear and tick Display Equation on chart and Display R-squared value on chart. That gives you the regression line and its statistics in one pass. The steps below cover the exact menus, the mistakes that break the line, and what to do when the option is greyed out.

What You'll Need

  • Excel for Windows or Mac (the steps below use the desktop app; the web version has a reduced trendline pane).
  • Two columns of numeric data: one independent variable (X) and one dependent variable (Y), with no blank rows inside the range.
  • A scatter chart, not a line chart. Trendlines work on scatter, column, bar, and line charts, but a scatter chart is the correct choice for regression because it treats both axes as numeric.

Step-by-Step

  1. Lay out your data cleanly. Put X values in one column and Y values in the next, with a header row. Remove text, blanks, and error values like #N/A from the numeric range; a single blank can shift the fitted line.
  2. Select the two columns including headers, then go to Insert > Scatter and pick Scatter (markers only). Avoid Line charts here; they connect points in row order and do not fit a regression.
  3. Right-click any data point on the chart and choose Add Trendline. If the context menu does not show it, click the chart once, then use Chart Design > Add Chart Element > Trendline > Linear. Menu labels vary slightly by Excel version and platform.
  4. In the Format Trendline pane, confirm Linear is selected. For a simple straight-line fit, leave Order alone (it only appears for polynomial).
  5. Tick Display Equation on chart and Display R-squared value on chart. The equation appears as y = mx + b, where m is the slope and b the intercept. R-squared tells you how much of the variation in Y is explained by X; closer to 1 is a tighter fit.
  6. Optionally set a forecast. Under Forecast, enter a number in Forward or Backward to extend the line beyond your data range. Leave it at 0 if you only want the fitted line.
  7. Close the pane. The line and labels stay on the chart and update automatically if you edit the source data.
  8. For exact coefficients, skip the chart label and use =SLOPE(known_ys, known_xs), =INTERCEPT(known_ys, known_xs), and =RSQ(known_ys, known_xs) in cells. These give more decimal places than the on-chart label, which rounds to a few digits.

Common Mistakes

  • Using a line chart instead of a scatter. A line chart treats the X axis as categories, so the trendline is fitted against row numbers, not your X values. The equation will look plausible but be wrong.
  • Including headers or text in the range. Excel may plot the header as a series or drop points silently. Keep the numeric range pure.
  • Leaving blank cells. Gaps can be plotted as zero or skipped depending on chart settings, distorting the slope. Fill or delete incomplete rows before charting.
  • Reading the rounded equation as exact. The on-chart label rounds coefficients. Use SLOPE and INTERCEPT for precise values.
  • Adding a trendline to a stacked or 3-D chart. Trendlines are not available on stacked, 3-D, radar, pie, or doughnut charts. Switch to a 2-D scatter.
  • Assuming correlation proves causation. A high R-squared shows fit, not cause.

Tips

  • Format the trendline separately from the series: right-click the line, choose Format Trendline, and set a distinct colour and dash style so it stands out from the markers.
  • To show the equation with more precision, format the label text box and increase decimal places, or pull the values from SLOPE/INTERCEPT into cells and build your own label.
  • If you have multiple series, add a trendline per series and label each one so readers know which equation belongs to which group.
  • For a quick visual check, add a second trendline type (for example exponential) and compare R-squared values before deciding linear is appropriate.
  • Keep the source data on its own sheet and chart from there; editing data in place updates the line without rebuilding the chart.

Troubleshooting

  • Add Trendline is greyed out: you are likely on a stacked, 3-D, pie, radar, or doughnut chart, or the chart has no numeric series. Change the chart type to a 2-D scatter.
  • The line is flat or missing: check that the X column is numeric, not text formatted as numbers. Select the column, use Data > Text to Columns > Finish, and confirm the values right-align.
  • The equation looks wrong: verify the X and Y ranges are the ones you intend. In the Format Trendline pane, the series name at the top tells you which data the line is fitted to.
  • R-squared does not appear: the checkbox is in the same pane as the equation; if the pane is collapsed, click the trendline once to reopen it.
  • The line does not extend: set Forward or Backward under Forecast to a positive number.
  • Excel web version: the trendline options are more limited; for full control, open the file in the desktop app.

Frequently Asked Questions

Can I add a linear regression line to a column chart?

Yes, Excel allows a trendline on a 2-D column chart, but a scatter chart is the correct choice when both variables are numeric, because a column chart treats the X axis as categories.

How do I get the slope and intercept as numbers?

Use =SLOPE(known_ys, known_xs) and =INTERCEPT(known_ys, known_xs). They return full-precision values, unlike the rounded on-chart equation.

Why is my trendline option missing?

Trendlines are not supported on stacked, 3-D, pie, doughnut, or radar charts. Switch to a 2-D scatter or column chart.

Does the trendline update when I change the data?

Yes, if the chart is linked to the cells. Edit a value and the line and equation recalculate automatically.

What does R-squared mean on the chart?

It is the proportion of variance in Y explained by X, from 0 to 1. A value near 1 means the points sit close to the line; it does not prove that X causes Y.

Can I add more than one trendline?

Yes. Right-click a different series and add a trendline to each, or add a second trendline to the same series to compare fit types.