Sometimes a chart does not show the data in the order you want. To sort data on an Excel chart, you must sort the source data range first, then the chart updates automatically. You can do this quickly using the Sort feature on the Data tab or by dragging and dropping headers in the spreadsheet.
What You'll Need
- A computer with Microsoft Excel installed (desktop or online version).
- A worksheet containing at least one chart and the data it is linked to.
- A clear idea of the data order you want to display (e.g., highest to lowest or alphabetical).
Step-by-Step
- Open your workbook. Click on the Excel file that contains the chart you want to modify. Make sure the worksheet with the chart is visible in the main window.
- Select the data source. Click on any cell within the table of data that feeds the chart. It is usually best to click on the top-left cell of the range (often containing a header like "Region") and then drag your mouse down to include all the rows and columns used by the chart. Alternatively, use the mouse to select the entire table, including the headers and the empty rows below the data if they were used to create the chart.
- Go to the Data tab. Look at the top ribbon in Excel and click on the "Data" tab. This tab contains tools for managing data sets, including sorting and filtering.
- Use the Sort button. On the far left side of the Data tab, locate the "Sort" button (it looks like A with an arrow down). Click it to open the Sort dialog box.
- Choose the primary sort key. In the "Sort by" dropdown menu, select the column header you want to use to order the chart. For example, if you want to sort by sales figures, select "Sales Amount". If you want to sort alphabetically by region, select "Region".
- Select the sort order. In the "Sort On" dropdown menu, choose "Cell Values". This ensures Excel sorts the text or numbers exactly as they appear. In the "Order" dropdown menu, choose your desired sequence. For numbers, select "Smallest to Largest" or "Largest to Smallest". For text, select "A to Z" or "Z to A". You can also choose to sort by color if your data has conditional formatting applied.
- Check "My list has headers". Ensure the checkbox labeled "My list has headers" is checked. This tells Excel that the first row contains names for the columns and should not be included in the sorting process. If this is unchecked, Excel will try to sort the header names along with the data, which will likely result in an error or a broken chart.
- Apply the sort. Click the "OK" button at the bottom of the dialog box. Excel will now rearrange the rows in your data table according to your criteria.
- Verify the chart update. Watch the chart in your spreadsheet. It should immediately redraw itself to reflect the new order of the data. For example, if you sorted a column of months from January to December, the chart bars or points will now appear in chronological order.
- Handle multiple levels (optional). If you want a secondary sort (for example, sort by Sales Amount first, and then by Region for items with the same sales number), click the "Add Level" button in the Sort dialog box. Repeat steps 5 through 7 for the new level. Excel will use the first level to break ties, then the second level to further organize the data.
- Save your work. Once you are satisfied with the new order, remember to save the file so you do not lose your changes.
Common Mistakes
- Sorting only the chart, not the data. A common error is trying to right-click on the chart and select a sort option. Excel does not allow you to sort the chart elements directly. You must sort the underlying data table, and the chart will follow. If you right-click the chart, you will only be able to change the chart type, layout, or data source, not the order of the data.
- Forgetting to select the entire range. If you select only a small part of your data table (for example, just the last few months), Excel will only sort those selected cells. The chart, which is linked to the entire table, will likely show an error or display incorrect data. Always ensure the whole data set is highlighted before using the Sort button.
- Leaving "My list has headers" unchecked. When you have a header row at the top of your data, it is crucial to keep this option checked. If it is unchecked, Excel will treat the header names like data and try to sort them into the list. This often results in a "Sort operation failed" error or data that is completely out of order.
- Sorting columns instead of rows. Charts typically display data in a vertical orientation (rows). If you sort a horizontal column of data, the chart will not update correctly because the vertical relationship between the category and the value is broken. Always sort the rows of your data table.
Tips
- Create a backup copy. Before making major changes to your data, it is good practice to save a copy of the file. This way, if you accidentally sort the data into an unwanted order, you can simply close the file without saving and reopen the original copy.
- Use the Filter button for quick sorting. If you are comfortable with Excel filters, you can click the "Filter" button (the funnel icon) on the Data tab. This will add drop-down arrows to your headers. You can click on these arrows to sort specific columns visually without opening the full Sort dialog box.
- Sorting by Color. If you have used conditional formatting to color-code your data (e.g., highlighting low values in red and high values in green), you can sort by color directly from the Sort dialog box. This is useful for quickly separating your best and worst performers.
- Using the Sort & Filter dropdown. On the Home tab, there is a small dropdown arrow next to the Sort & Filter icon. Selecting "Sort A to Z" or "Sort Z to A" from this menu will sort the selected range immediately without asking for additional configuration.
Troubleshooting
If the chart does not update after you sort the data, check the following:
- Check for hidden rows. Sometimes, hidden rows in the data table can cause the chart to look incorrect. Click on a row number in the leftmost margin to select the whole sheet. Right-click and choose "Unhide" to make sure no data is being omitted from the chart's view.
- Ensure the chart is not linked to a separate range. Some charts are created by selecting a range of cells and then pressing the F11 key to insert a chart on a separate sheet. If the chart is on a separate sheet, you must sort the data on the original data sheet. The link between the two sheets will automatically update the chart when you save or refresh the workbook.
- Verify the data type. If Excel is treating numbers as text (for example, numbers with leading spaces), the sort order may not work as expected. You can use the "TRIM" and "TEXT" functions to clean the data, or the "Convert to Number" feature in the "Data" tab.
- Sort on the correct axis. If you are working with a bar chart, the horizontal axis usually represents the values and the vertical axis represents the categories. Make sure you are sorting the data in the column that corresponds to the axis you want to change. For a bar chart, sorting the "Category" column will reorder the bars left to right.
Frequently Asked Questions
Can I sort a chart by clicking on it?
No, you cannot sort a chart directly by clicking on it. Excel charts are linked to the data source in the spreadsheet. You must sort the data in your worksheet first, and the chart will automatically update to reflect the new order.
Why does the chart show an error after sorting?
The chart may show an error if the sort operation was applied to a subset of the data rather than the entire range, or if the "My list has headers" option was left unchecked. Check the data range selection and the sort dialog box settings to ensure they are correct.
How do I sort a chart by the legend items?
You cannot sort a chart by the legend items directly. The legend is simply a visual key that corresponds to the data series in the chart. To rearrange the items in the legend, you must rearrange the data series in the data table.
Does sorting the data affect the formulas in the spreadsheet?
Yes, sorting data will change the order of the rows. This will affect any formulas that reference specific rows by number. For example, if you have a formula that calculates the sum of the first 10 rows, that sum will change once you sort the data and the rows are no longer the first 10 rows.
Can I sort a chart dynamically with a slicer?
Yes, you can use a slicer to filter the data that appears in a chart. While a slicer does not strictly "sort" the data from smallest to largest, it allows you to dynamically change which data points are displayed, which can effectively reorder the chart based on your selection.
What if the chart is not updating when I save the file?
Excel generally updates charts automatically when you save the file. However, if you are working in a very large workbook with complex formulas, the chart may not update until you click on the chart or press the "Refresh All" button on the Data tab.