How to Add a Vertical Line to a Line Chart in Google Sheets

Using an additional series that contains two data points, we can add a vertical line to a line chart in Google Sheets. However, this depends on the formatting of the category/horizontal axis (x-axis). If your category axis contains numeric, date, or time values, the method will work as expected.

The x-axis in a line chart typically contains dates, months, or years since it is used to visualize changes in values over time.

Purpose of Adding a Vertical Line to a Line Chart

Adding a vertical line to a line chart in Google Sheets helps highlight key dates, events, or thresholds, making data interpretation easier. It can mark significant moments such as a policy change or deadline, allowing for a clearer analysis of trends before and after the event.

A vertical line also helps compare different data segments, visually separating phases for better insights. Additionally, it can indicate benchmarks or targets, such as sales goals or critical thresholds, making it easier to assess performance.

In short, by enhancing readability and supporting decision-making, a vertical line improves the overall effectiveness of data visualization in Google Sheets.

Adding a Vertical Line to a Line Chart with One Series

1. Understanding the Data

In the following example, the category axis contains dates. The source data is in the range B1:C, where B2, B3, B4… contain 1/1/22, 1/2/22, 1/3/22, etc. This means the x-axis consists of dates. There is only one series (y-axis), which is in the range C1:C.

MonthAmount 1
01/01/2022100
01/02/2022150
01/03/202225
01/04/2022175
01/05/2022100
01/06/2022250
01/07/2022150
01/08/2022100
01/09/202275
01/10/2022100
01/11/2022150
01/12/2022150

Here are the required steps to add a vertical line to a line chart in Google Sheets:

2. Positioning the Vertical Line on the Category Axis

We will use cell E1 to control the position of the vertical line. To do this, create a drop-down menu in E1 with category values.

  1. Navigate to cell E1.
  2. Click Insert > Drop-down.
  3. In the Data validation rules panel, select Drop-down (from a range) under Criteria.
  4. In the field below, enter B2:B and click Done.
  5. Now, in the drop-down menu in E1, select any date, for example, 01/04/2022.
Sample data and control drop-down using data validation to position a vertical line in Google Sheets

3. Helper Range (Source Data for the Chart)

In cell F1, enter the following formula to generate the helper table for the chart:

=IFNA(VSTACK(HSTACK(FILTER(B1:C, CHOOSECOLS(B1:C, 1)<>""), "Focus Line"), VSTACK(HSTACK(E1, ,0), HSTACK(E1, , MAX(CHOOSECOLS(B1:C, 2))))))

Where B1:C is the source data range, and E1 is the cell containing the date on the x-axis that controls the position of the vertical line in the line chart. This formula will generate the required range in F1:H for plotting the chart.

Helper range for creating a line chart with an added vertical line in Google Sheets

4. Formatting the Data

You may need to format the date in F2:F.

  1. Navigate to cell B2.
  2. Right-click and select Copy.
  3. Select F2:F.
  4. Right-click and select Paste Special > Format Only.

5. Creating and Adding a Vertical Line to a Line Chart

Select F1:H and go to Insert > Chart to create a line chart with a vertical line.

Example of a line chart with a vertical line in Google Sheets

If the vertical line does not appear as expected, check the settings in the Chart Editor against the ones below. Also, compare them with the sample sheet provided at the end of this post.

Chart Editor – Setup Tab:

  • Chart Type: Line Chart
  • Data Range: F1:H15
  • X-axis: Month
  • Series:
    • Amount 1
    • Focus Line
  • Options:
    • Use Row 1 as Headers
    • Use Column F as Labels

Formula Logic and Explanation

To add a vertical line to a line chart, we need to create a helper series with two data points—one containing 0 and the other containing the maximum value in the series.

Explanation:

=IFNA(VSTACK(HSTACK(FILTER(B1:C, CHOOSECOLS(B1:C, 1)<>""), "Focus Line"), VSTACK(HSTACK(E1, , 0), HSTACK(E1, , MAX(CHOOSECOLS(B1:C, 2))))))
  • FILTER(B1:C, CHOOSECOLS(B1:C, 1)<>"") – Filters the source data to remove empty rows.
  • HSTACK(..., "Focus Line") – Adds a third column with the title “Focus Line”.
  • VSTACK(HSTACK(E1, ,0), HSTACK(E1, ,MAX(CHOOSECOLS(B1:C, 2)))) – Vertically stacks two rows: the first row contains 0, and the second row contains the maximum value in the third column. The first column will be the control date from the drop-down.

This setup allows us to add a vertical line to the line chart in Google Sheets.

Adding a Vertical Line to a Line Chart with Two or More Series

In the first example, we used only one series, labeled “Amount 1”. However, if we have two series, such as “Amount 1” and “Amount 2”, the data will be in columns B1:D, with the control drop-down in cell F1.

Here is the modified formula:

=IFNA(VSTACK(HSTACK(FILTER(B1:D, CHOOSECOLS(B1:D, 1)<>""), "Focus Line"), VSTACK(HSTACK(F1, , , 0), HSTACK(F1, , , MAX(CHOOSECOLS(B1:D, {2, 3}))))))

In this formula, B1:D is the range containing the source data, and F1 is the control drop-down. We modified HSTACK(F1, , ,0) and HSTACK(F1, , , MAX(CHOOSECOLS(B1:D, {2, 3}))), adding three commas instead of two. Additionally, the MAX function now considers two columns {2, 3}.

Sample data, vertical line control, and helper data for a two-series line chart in Google Sheets

If you have three series, the formula adjusts accordingly:

=IFNA(VSTACK(HSTACK(FILTER(B1:E, CHOOSECOLS(B1:E, 1)<>""), "Focus Line"), VSTACK(HSTACK(F1, , , , 0), HSTACK(F1, , , , MAX(CHOOSECOLS(B1:D, {2, 3, 4}))))))

In this version, the formula now includes four commas in HSTACK(F1, , , , 0) and HSTACK(F1, , , , MAX(CHOOSECOLS(B1:E, {2, 3, 4}))) to accommodate three series.

Sample Sheet

Sample Sheet

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

Mode of Comma-Separated Numbers in Excel (Dynamic Array)

There is no dedicated function in Excel to directly find the mode of comma-separated...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

More like this

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.