How to Display the Formula and Slope on an Excel Line Chart, Generating the Function Expression
Explain the steps for adding a linear trendline to an Excel line chart, displaying the equation and R² value, and describe how to use the SLOPE and INTERCEPT functions to verify the slope, and how to generate the function expression as cell text.
Key points of this article
- Adding a linear trendline to a line chart and checking "Display Equation on chart" shows a label of the form y = kx + b, where k is the slope and b is the intercept.
- The SLOPE and INTERCEPT functions can calculate the slope and intercept into cells, and the results can be referenced by other formulas.
- Using the TEXT function to concatenate strings lets you turn a formula result into text with a controlled number of decimal places, for use in a report.
- A line chart treats the horizontal axis as evenly spaced categories by default, so when x values are unevenly spaced the slope will be distorted; use a scatter chart instead.
- An R² close to 1 indicates a good linear fit; when it is low, consider switching to an exponential, logarithmic, or polynomial trendline.
If you have used an Excel line chart to organize a set of experimental data, monthly sales, or course grades, you have probably wondered what pattern the data follows overall. Inserting a line chart is easy, but many people don't know where the formula for the trendline is hidden or which number in the formula corresponds to the slope, so they end up calculating it by hand.
This piece is for readers who need to do trend analysis, course reports, or business reviews. After reading it, you will be able to display the trendline equation on an Excel line chart, read the slope and intercept from that equation, and use functions to calculate them and assemble a function expression that can go into a table or report.
How to display the formula and slope on a line chart? One-sentence conclusion
The straightforward approach: add a linear trendline to the line chart, then in the trendline options check "Display Equation on chart" and "Display R-squared value on chart," and the expression in the form y = kx + b will appear on the chart. If you need to put the slope into a cell for further calculation, use the SLOPE function to retrieve it.
| Your situation | Recommended Practices | Cause |
|---|---|---|
| The data is roughly a straight line; I just want to see the formula. | Add a linear trendline to the line chart, and check the option to display the equation. | Read y = kx + b directly from the graph, which requires fewer steps. |
| Need to put the slope into the table and continue the calculation | Using the SLOPE function to compute values over a data range | The result is in a cell, so it can be referenced by other formulas. |
| I want to write the formula as a paragraph of text and include it in the report. | Concatenate a "y = …" string using the TEXT function | The number of decimal places is controllable, so labels will not be cut off or displayed incompletely. |
| The data is curved, so the R² from a straight-line fit is very low. | Change to an exponential, logarithmic, or polynomial trendline | Linear formulas can mislead judgment; you should check the goodness of fit first before choosing the model type. |
| The x-axis is dates or numeric values with uneven spacing. | Switch to a scatter plot with data points | The line chart treats the horizontal axis as evenly spaced categories by default, so the slopes become distorted. |
Before You Begin: Confirm These Points First
Before you start, confirm the following items; otherwise, however tidy the computed slope is, it may still be meaningless.
- Whether x and y are numeric values. If numbers are stored as text, charts and functions may treat them as 0 or ignore them entirely, and the trendline will not match the data. Select the data and check whether the status bar shows a sum; this is a quick way to tell.
- Whether the x-axis intervals are equal. A line chart places categories on the horizontal axis one after another. When x values are unevenly spaced, such as 1, 2, 4, 8, the chart looks like a straight line, but the slope no longer reflects the true proportion. In that case, a scatter plot should be used.
- Whether the data really lies close to a straight line. A slope only describes a linear relationship. When the scatter points clearly curve, the slope given by a linear formula can only represent a local trend.
- What the unit of the slope is. The unit of the slope is the unit of y divided by the unit of x. If x is days and y is units sold, the slope means "how many more units are sold per day," and the unit should be included when writing the report.
Steps to Display the Trendline Formula on an Excel Line Chart
- Organize the data: put the x values (such as time points or numerical experimental conditions) in one column, and the corresponding y values in the adjacent column, with no blank rows in between.
- Select the two columns of data and insert a line chart. It is recommended to choose a style with data markers, so it is easier to see where each point is.
- Click the chart to select it, then click the plus button beside the chart (Chart Elements), check Trendline, and choose the Linear type.
- Right-click the trendline to open the Format Trendline panel, then check Display Equation on chart and Display R-squared value on chart.
- The chart will show a label in the form y = kx + b, where k is the slope and b is the intercept. If the label does not show enough decimal places, select the label and add decimal places in the number format settings.
- In an empty cell, enter =SLOPE(y range, x range) to get the slope, and compare it with k in the label on the chart.
- If you need the formula as text, enter ="y = "&TEXT(SLOPE(B2:B13,A2:A13),"0.000")&"x + "&TEXT(INTERCEPT(B2:B13,A2:A13),"0.000") in a cell, replacing the ranges with your actual ranges. If the intercept is negative, the result will show "+ -", so manually change it to a minus sign.
- To forecast future values, set the number of periods to forecast forward in the Format Trendline panel, and the chart will extend the trendline out.
Verify each item after completion
Once you have the formula and the slope, I recommend checking each item, especially when these numbers will be used in your report.
| Checklist item | How do you see it? | What should I do if I have a problem? |
|---|---|---|
| Are the slopes consistent? | The label k on the plot is the same as the result of SLOPE. | Inconsistencies are usually caused by selecting the wrong data range. Re-select the two columns. |
| Is the data point complete? | The number of data points in the chart matches the number of rows in the table. | Check for empty cells, numbers stored as text, and redundant header rows |
| Goodness of fit | R² close to 1 indicates a better fit of the line. | When the value is too low, switch the curve type, or split the data into segments and fit each one separately. |
| Is the horizontal axis equally spaced? | Check whether the tick marks on the horizontal axis are evenly spaced. | When the spacing is uneven, switch to a scatter plot and add the trend line again. |
| Is the conclusion reasonable? | The sign of the slope is consistent with the trend of the graph, and the units are consistent with the business meaning. | Note the units and scope of applicability in the report, and do not extrapolate beyond the data. |
📊 Core Comparison
There are three common methods for obtaining the slope; they produce the same result, and the difference lies in where the result is placed.
| Method | Where are the results? | Suitable scenarios |
|---|---|---|
| Chart trendline labels | Shown only in the figure; cannot be directly cited. | Quick image viewing and presentation for leadership |
| SLOPE and INTERCEPT functions | Within a cell, it can be referenced by other formulas. | Need to continue the calculation, make a prediction, or run a check |
| String concatenation function | The cell contains a piece of text. | I need to write the formula into a report or documentation |
❓ Frequently Asked Questions (FAQ)
1. How do I change the number of decimal places in a trendline equation that shows too many or too few?
Select the equation label on the chart and set the number of decimal places in the number format. If you need exact values, use the SLOPE and INTERCEPT functions to get them directly, then use the TEXT function to specify the number of digits. This is more reliable than relying on the label on the chart.
2. Why doesn't the slope of the line chart match my hand calculation?
There are two common causes: first, a line chart treats the horizontal axis as evenly spaced categories, so when the x values are unevenly spaced the results come out skewed; second, the data range includes headers or empty cells. Switching to a scatter chart and checking the data range will resolve most of these problems.
3. Data looks like a curve — can this method still be used?
Yes, but change the trendline type. In the trendline format options, try exponential, logarithmic, and polynomial in turn, compare their R² values, and choose the one that fits better and matches the business pattern. The formula for a curve-type trendline is no longer a simple slope, so the report should state the trendline type.
4. When the intercept in a formula is negative, how should the assembled text be displayed correctly?
The concatenation would display a negative intercept as "+ -". You can use an IF function to check whether the intercept is positive or negative, using a plus sign for positive values and a minus sign for negative ones; if it is only going into a report, manually changing the sign is also quick.
📝 Summary
Displaying the formula and slope on an Excel line chart comes down to adding a linear trendline and checking the "Display Equation on chart" option, then using the SLOPE and INTERCEPT functions to verify the values and produce results you can reference. Whether the horizontal axis is evenly spaced and how well the line fits determine whether the slope can be interpreted correctly.


