Excel Line Chart Makeover: From Ugly to Awesome

A line chart with eight overlapping lines is basically a plate of spaghetti. Everyone can see something is happening, but nobody can tell what.

In this post, we'll do a full line chart makeover using Pivot Tables, a slicer, and three modern Excel array functions: TRIMRANGE, DROP, and HSTACK.

The result is an interactive chart where one click highlights any single trend against the rest of the group, and the whole thing expands automatically when new data arrives.

Download the Excel Files

Complete the form below to instantly access the Excel files and Excel Formula Prompting Guide.

Video Tutorial

https://www.youtube.com/watch?v=Ko34S2tWauk

Watch on YouTube & Subscribe to our Channel

The Setup: A Pivot Table for Chart Data

The scenario here is an e-bike rental shop that tracks a weekly health score for each bike in their fleet. The maintenance team wants to see how those scores trend over time and quickly spot which bike might need attention.

We start by building a Pivot Table with Week in the Rows area, Bike ID in the Columns area, and Health Score as the Values. This gives us one health score per bike per week in a clean grid, which is exactly what a line chart needs.

Set up the Pivot Table with Week in Rows, Bike ID in Columns, and Health Score in Values. This grid structure feeds directly into our chart.

Before building the chart, remove the Grand Totals from both rows and columns. Right-click anywhere in the Pivot Table, go to PivotTable Options, and turn them off. Clean data in means a clean chart out.

Next, rename this sheet “All Chart Data.” Then duplicate it by holding Ctrl and dragging the tab to the right. Rename the copy “Selected Data.” The slicer will connect only to the Selected Data pivot table, filtering it down to one bike at a time while the All Chart Data sheet always shows the full fleet.

Using TRIMRANGE to Pull the Pivot Table into a Spill Range

Create a new sheet called “Chart” (or “Chart Data”). This is where we'll build the combined data source for our chart. We want to pull the live Pivot Table data from both sheets into this one range, and we'll start with TRIMRANGE.

Here's a quick look at the TRIMRANGE function. It returns the used portion of a range, trimming away any empty rows or columns at the edges. The function arguments are:
  • range: the range to trim, which can reference an entire sheet
  • row_trim_mode: controls trimming of empty rows from the top and/or bottom (optional)
  • col_trim_mode: controls trimming of empty columns from the left and/or right (optional)

Click in cell A1 of the Chart sheet and enter a TRIMRANGE formula that references every cell on the All Chart Data sheet. Clicking the top-left corner of a sheet tab creates a reference to all rows on that sheet.

=TRIMRANGE('All Chart Data'!1:1048576)
The TRIMRANGE formula references the entire All Chart Data sheet using the row range 1:1048576, which automatically picks up only the used rows and columns.

Once entered, TRIMRANGE spills the full Pivot Table data onto the Chart sheet. You'll notice it looks right at first glance, but there's a problem at the top: a header row filled with zeros has come along for the ride. That happens because the Pivot Table column headers are numeric Bike IDs, and Excel treats them as zeros in the spill output. We'll clean that up next.

TRIMRANGE spills all Pivot Table data onto the Chart sheet, but notice the extra header row of zeros at the top. We'll remove that next with DROP.

Cleaning the Data with DROP

The spill range includes an unwanted header row of zeros at the top. The DROP function removes it cleanly without any manual adjustments.

Before diving in, a quick look at the DROP function. It returns an array with a specified number of rows or columns removed from the beginning or end. The function arguments are:
  • array: the array or range to drop from
  • rows: number of rows to drop from the top (use a negative number to drop from the bottom)
  • columns: number of columns to drop from the left (use a negative number to drop from the right) (optional)

Wrap the TRIMRANGE formula inside DROP and tell it to remove the first row. This strips the zero-filled header and leaves only the real Pivot Table data.

=DROP(TRIMRANGE('All Chart Data'!1:1048576),1)
Wrapping TRIMRANGE in DROP with a rows argument of 1 removes the unwanted zero header row from the spilled output.
The result is a clean spill range showing all bike health scores by week, ready to combine with the selected bike data.

Combining Both Pivot Tables with HSTACK

Now we need to add the Selected Data Pivot Table alongside the All Chart Data. HSTACK joins two arrays side by side in a single spill range.

A brief word on the HSTACK function. It appends arrays together horizontally, returning a combined array with more columns. The function arguments are:
  • array1: the first array or range
  • array2, …: one or more additional arrays to append to the right of the previous array (optional)

Edit the formula in cell A1 and wrap the existing DROP+TRIMRANGE expression inside HSTACK as the first array. For the second array, apply the same DROP+TRIMRANGE pattern to the Selected Data sheet.

=HSTACK(DROP(TRIMRANGE('All Chart Data'!1:1048576),1),DROP(TRIMRANGE('Selected Data'!1:1048576),1))
HSTACK combines the All Chart Data and Selected Data ranges side by side. Notice the slicer on the right is already filtering the Selected Data pivot to B-101.
The combined range has a problem: a duplicate Week column appears between the two data sets. We'll use the columns argument of DROP to remove it.

Removing the Duplicate Week Column

The Selected Data Pivot Table includes its own Week labels column, which creates a redundant column in the middle of the combined range. The DROP function accepts a columns argument to cut it out.

Update the second DROP call to also drop 1 column from the left. This removes the Week labels from the Selected Data array before HSTACK joins it to the right.

=HSTACK(DROP(TRIMRANGE('All Chart Data'!1:1048576),1),DROP(TRIMRANGE('Selected Data'!1:1048576),1,1))
Adding a columns argument of 1 to the second DROP call removes the redundant Week label column from the Selected Data array before stacking.
The final combined range shows all bikes from the full fleet plus the currently selected bike appended as an extra column at the right edge.

Building the Chart on the Spill Range

Cut the slicer from the Selected Data sheet and paste it onto the Chart sheet. When the slicer filters the Selected Data Pivot Table, only the last column in the spill range changes. Everything else stays the same.

Select the entire spill range, go to Insert, and insert a regular 2D Line chart (not a Pivot Chart). Once inserted, click Switch Row/Column under Chart Design so the weeks appear along the bottom axis.

The initial line chart shows all bikes plus the selected bike as a duplicate series. The slicer on the right already reflects bike B-103 as the highlighted selection.

Styling the Chart for Clarity

Select each background line (all bikes except the highlighted one) and change the Shape Outline to a light gray. If a line is hidden behind others, use the dropdown in the Format tab to select it by name.

For the selected bike line, change the outline to a bright color like green, increase the line weight, and add circular markers through Format Data Series. Setting the marker fill to white gives it a bike-chain look that works nicely for this dataset. Remove the legend if you prefer a cleaner look.

After styling, the selected bike (B-102) stands out as a bright green line with circular markers while all other bikes fade into light gray. Click any slicer item to shift the highlight instantly.

The Chart Expands Automatically with New Data

Because the chart source is a spill range, it updates whenever the spill range changes. To add new weeks, paste new rows into the source data table. The Pivot Tables extend automatically since the source is an Excel Table.

Right-click either Pivot Table and choose Refresh. Both pivot tables update at once. The TRIMRANGE formula picks up the new rows, DROP and HSTACK rebuild the combined range, and the chart adds the new week with zero manual intervention.

After pasting Week 07 data and refreshing the Pivot Tables, the chart automatically extends to show the new week without any changes to the formula or chart source range.

Taking It Further: A Dark Mode Version

The same chart looks completely different with a dark background, and it is easier to achieve than it sounds. Change the chart area and plot area fill to a dark color, then update all font colors to white or light gray so labels and axis values remain readable. The gray background lines stay subtle, and the bright green selected line pops even more against a dark canvas.

The slicer gets the same treatment. Right-click the slicer, open Slicer Styles, and duplicate an existing style. From there you can control the background, font color, and border for every element, including selected and unselected items. Turning off the slicer header in Slicer Settings also removes the clear and multi-select buttons, keeping the UI focused on single-bike selection. The end result is a dashboard-quality chart that fits right into a dark-themed report.

The dark mode version uses a dark chart background, light-colored labels, and a custom slicer style to create a polished dashboard look with the same underlying data and formulas.

Summary

This technique turns a cluttered multi-line chart into a focused, interactive visualization by combining two Pivot Tables into one dynamic source range.

TRIMRANGE captures only the used data on each pivot sheet. DROP strips unwanted header rows and the duplicate week column. HSTACK joins both arrays side by side so the selected bike always appears as an extra series the chart can highlight independently.

Connect a slicer to the Selected Data pivot table, style the background lines gray and the selected line a bold color, and you have a chart that practically reads itself. Add new data to the source table, refresh, and the chart grows with it automatically.

And if you want to take the presentation up a notch, the same chart translates beautifully into a dark mode layout with a custom slicer style.

Add comment

Your email address will not be published. Required fields are marked *

Generic filters

Excel Shortcuts List

keyboard shortcuts list banner

Learn over 270 Excel keyboard & mouse shortcuts for Windows & Mac.

Excel Shortcuts List

Join Our Weekly Newsletter

The Excel Pro Tips Newsletter is packed with tips & techniques to help you master Excel.

Join Our Free Newsletter