If you want to learn how to create a line graph in Excel, follow along with this effortless Microsoft Excel tutorial.
You commonly use a line graph to track changes over time, showcasing trends, growth, or declines within a continuous dataset. This data visualization is particularly effective for visualizing data that changes regularly, such as monthly sales figures, daily temperatures, or yearly population growth.
Read on as I explain various methods of making a line graph in Excel for different datasets, use cases, and level of expertise.
Using the Default Chart Hotkey
Is the input dataset for the chart already organized like the one shown above? Then follow these steps:
Select the whole dataset and press Alt + F1.
You’ll see an automatic column chart on the worksheet. Click on that to open the Chart Design tab.
Go to the Chart Design tab and click on the Change Chart Type command.
The All Charts tab will open on the Change Chart Type dialog box.
Choose Line from the left side navigation panel.
Select the first line chart you see in the dialog box. Click OK to replace the default chart with a line chart.
Using the Quick Analysis Tool
Highlight the input dataset and press Ctrl + Q to launch the Quick Analysis tool in the bottom right corner of the selected dataset.
Navigate to the Charts tab and click on the More option.
This will open the Insert Chart dialog box.
Navigate to the All Charts tab and click on the Line category in the left-side navigation panel.
Now you can choose from various line graphs, like the ones listed below:
- Basic Line chart: Connects data points with lines to show trends over categories or time.
- Stacked Line: Layers the data series lines on top of each other, showing how each contributes to the total value.
- 100% Stacked Line: Similar to a stacked line, each line represents a percentage of the total, always summing up to 100%.
- Line with Markers: Adds data point markers (like circles or squares) to a basic line chart for better visualization.
- Stacked Line with Markers: Combines stacked lines with markers for each data point on the stacked lines.
- 100% Stacked Line with Markers: Combines 100% stacked lines with markers for each data point on the percentage lines.
- 3-D Line: Presents a basic line chart with depth, but can be visually cluttered and harder to interpret.
Using the Recommended Charts Command
The Recommended Charts tool is the default location of all Excel data visualization graphs including line charts. Learn below how to use this command effortlessly:
In a line chart, category data are plotted over time. So, organize your dataset according to the example given above.
Select your input dataset and click on the Insert tab on the Excel ribbon.
Click on the Recommended Charts command inside the Charts commands block.
Now, you should see the Insert Charts dialog. There, you can choose the auto-populated line chart item in the left-side navigation tab.
Alternatively, click on the All Charts tab and choose any line chart you want to insert from the Line category menu on the left-side panel.
Click OK on the dialog box to add the line chart to the active worksheet.
Excel will insert the basic line graph as shown above.
You might want to customize the chart to present data effectively. Your first task is to add Data Labels for the categories plotted on the vertical axis or Y-axis.
Click on a category line on the graph and hit the Chart Elements icon. It’s the plus (+) icon in the top right right corner of the chart you’ve added. The icon will only show if you select the chart first.
On the Chart Elements context menu, checkmark the checkbox for Data Labels.
If you’ve selected the category that’s on the top and the Data Labels happen to also show up above the line, keep this as is.
However, when the Data Labels show below the category line, hover the cursor over the Data Labels option in the context menu. An arrow will show up. Click on that and choose Above as the position of Data Labels.
Now, repeat the above steps for the next category, which might be below the first one. For this line, click on the Data Labels expansion menu and choose the Below option.
The chart title helps the audience to get a context of the data being presented. So, customize it by double-clicking the Chart Title text box at the top of the line chart you’ve just added.
Find the final line graph that I created by following the same instructions given above.
Using the PivotChart Command
When the input dataset of the line chart changes dynamically as you update the workbook, you can use PivotChart.
Also, when your data requires multiple aggregations, like sales by region, then by product, then by time period, and so on, PivotCharts become handy. These charts allow you to aggregate and rearrange data effortlessly.
Moreover, if you need to create interactive reports where users can change the data view dynamically, PivotCharts provides a user-friendly way to interact with the data.
Navigate to the worksheet dataset you want to include in a PivotChart line graph. Select the data and click on the PivotChart command in the Charts block of the Insert tab.
The Create PivotChart dialog will open. It should automatically select the input data range on the worksheet.
Click on the Existing Worksheet radio button, and identify the destination range using the Location field.
Now, select the OK button on the dialog box to start creating the PivotChart as well as a PivotTable.
You should see the PivotCharts Fields navigation panel on the right side.
There, drag and drop the Month item of the data into the Axis (Categories) box at the bottom of the panel.
Now, drag the quantitative values, those you want to plot along the Y-axis into the Values box of the PivotCharts Fields panel.
You’ll see a column chart.
If the X-axis items aren’t organized in ascending order, you can change their positions in the PivotTable on the right by dragging and dropping one row at a time.
Once the row orders are corrected, click on the PivotChart and go to the Design tab.
Click on the Change Chart Type command and choose a line chart from the dialog box that follows.
Excel will change the existing column chart to a line graph instantly.
Creating Mini Linecharts Using Sparklines
For your time series data, you can also go for the Line sparklines in Excel to create line charts within the cell. This method allows you to visualize the trend data over a period of time in a small place or dashboard.
Not to mention, you can integrate sparklines with text paragraphs to illustrate points without breaking the flow of the text. This is useful in analytical reports, executive summaries, and other narrative formats.
For example, you’ve got a dataset as shown above for sales of different products for five consecutive quarters.
Select the entire dataset except for the column header texts.
Click on the Insert tab and select the Line command inside the Sparklines commands block.
The Create Sparklines dialog will show up. Click within the Location Range field and select the cell range adjacent to the right side of the target dataset.
That’s it! Your sparklines line charts are created inside the selected cell range.
Stock Quote Line Graph With Data Connection
If you wish to create a dynamically updated line chart for stocks, bonds, etc., you can use this method.
Create a Stock column in your worksheet and populate the names of NASDAQ-listed companies you want to monitor for price movements. Refer to the sample dataset screenshot given above.
Now, select the stock names in the column and click on the Stocks command inside the Data Types block of the Data tab.
Excel will match the company names with Microsoft’s proprietary stock quote API service and reformat the entries appropriately so the API can function.
If you see the information notification or question mark circle for any stock name in the list, that item doesn’t exist in the stock quote API. So, remove those entries to make the list of stocks fully compatible with the stock quote API.
Now, select all the stocks within the column and click on the tiny Insert Data icon in the top right corner of your selection.
This will open a context menu from which you can pick any of the following:
- 52 week high
- 52 week low
- Change
- Change (%)
- Currency
- Market cap
- P/E ratio
- Previous close
Find above a dynamic 52-week high stock price monitoring dataset created using the stock quote API.
Now, select the whole dataset and click on the Insert Line or Area Chart drop-down menu within the Charts block of the Insert tab.
From the context menu that opens, choose the Line with Markers graph.
In the chart you create, the 52-week high price quotes of various stocks in the dataset will be plotted on the Y-axis. In the X-axis, you’ll find the stock names.
The drawback of this method is it’s only available for Excel for the web, Excel for Microsoft 365 for Mac, and Excel for Microsoft 365. In older Excel editions, you won’t find this feature.
Using Excel VBA
You can fully automate the line chart creation and customization in Excel using VBA. You can either create a non-visual script that will simply execute the task it has been programmed for. Alternatively, you can create visual boxes to walk you or any other users throughout the process.
Before taking a deep dive into the script, learn how to create a VBA macro here:
📒 Read More: How To Use The VBA Code You Find Online
Now, you can use this script to create your own macro:
Sub CreateCustomLineChart()
Dim XRange As Range
Dim YRange1 As Range
Dim YRange2 As Range
Dim ChartTitle As String
Dim ChartObject As ChartObject
Dim Chart As Chart
' Step 1: Select X-axis dataset
On Error Resume Next
Set XRange = Application.InputBox("Select the X-axis data range:", Type:=8)
On Error GoTo 0
If XRange Is Nothing Then Exit Sub
' Step 2: Select first Y-axis dataset
On Error Resume Next
Set YRange1 = Application.InputBox("Select the first Y-axis data range:", Type:=8)
On Error GoTo 0
If YRange1 Is Nothing Then Exit Sub
' Step 3: Select second Y-axis dataset
On Error Resume Next
Set YRange2 = Application.InputBox("Select the second Y-axis data range:", Type:=8)
On Error GoTo 0
If YRange2 Is Nothing Then Exit Sub
' Step 4: Enter chart title
ChartTitle = InputBox("Enter the chart title:")
' Create the chart
Set ChartObject = ActiveSheet.ChartObjects.Add(Left:=100, Width:=375, Top:=75, Height:=225)
Set Chart = ChartObject.Chart
Chart.ChartType = xlLineMarkers
Chart.SetSourceData Source:=Union(XRange, YRange1, YRange2)
Chart.HasTitle = True
Chart.ChartTitle.Text = ChartTitle
' Add data labels to all series
Chart.ApplyDataLabels Type:=xlDataLabelsShowValue
Chart.SeriesCollection(1).DataLabels.Position = xlLabelPositionAbove
Chart.SeriesCollection(2).DataLabels.Position = xlLabelPositionBelow
' Adjust data label font size to prevent overlap
Chart.SeriesCollection(1).DataLabels.Font.Size = 10
Chart.SeriesCollection(2).DataLabels.Font.Size = 10
End Sub
The above script will do the following when you run the VBA macro:
- Show an input box so you can choose the dataset for the X-axis.
- There will be two more input boxes so you can choose two datasets for the Y-axis.
- You’ll also get the option to choose the chart title for your line graph.
As soon as you supply the above details accurately, Excel will create the line graph for you.
Conclusions
So far, you’ve learned how to create a line graph in Excel in 7 different ways.
If you’re new to Excel, practice the methods that utilize various Excel user interface commands.
However, if you want to automate the task or would like to give the programmatic approach a spin, try out the VBA-based method too.
If this in-depth Microsoft Excel article helped you to navigate the complicated space of Excel line graphs, you can share your acknowledgment below. If I missed a popular method to make a line graph, add that in your comment.
0 Comments