How to Change Bar Chart Width Based on Data in Excel (with Easy Steps)

We have the following dataset containing 4 groups of students with different weights, and each group contains various numbers of students. We will plot the bars with different widths according to the number of students.

excel bar chart width based on data


Step 1 – Arranging Values Using Formulas to Change the Bar Chart Width Based on Data

We have added a new dataset with 5 columns and a new column Indicator in the first dataset.

excel bar chart width based on data

In the first cell of the Number column, enter 0 as we want to have the range of the X-axis from 0 to 100.

arranging values

  • Use the following formula in cell B11.
=$C$4/SUM($C$4:$C$7)*100

$C$4 is the number of students in the P group, and $C$4:$C$7 is the range of the students in all of the 4 groups.

  • SUM($C$4:$C$7) → the SUM function will add the values in the range $C$4:$C$7.
    • Output → 210
  • $C$4/SUM($C$4:$C$7) → becomes
    • 20/210
    • Output → 0.0952380952
  • $C$4/SUM($C$4:$C$7)*100 → becomes
    • 0952380952*100
    • Output → 9.52380952

arranging values

  • Press Enter and drag down the Fill Handle tool to copy to cell B12.

excel bar chart width based on data

We will get the same value 9.52380952 in the two cells B11 and B12.

arranging values

  • Apply the following formula in cells B13 and B14.
=($C$5/SUM($C$4:$C$7)*100)+$B$12

$C$5 is the number of students in the Q group and $C$4:$C$7 is the range of the students in all of the 4 groups. $B$12 is the number in the previous cell.

  • SUM($C$4:$C$7) → the SUM function will add the values in the range $C$4:$C$7.
    • Output → 210
  • $C$5/SUM($C$4:$C$7) → becomes
    • 50/210
    • Output → 0.2380952380
  • $C$5/SUM($C$4:$C$7)*100 → turns into
    • 2380952380*100
    • Output → 23.80952380
  • ($C$5/SUM($C$4:$C$7)*100)+$B$12 → becomes
    • 80952380+9.52380952
    • Output → 33.333333333

arranging values

  • Use the following formula for cells B15 and B16.
=($C$6/SUM($C$4:$C$7)*100)+$B$14

excel bar chart width based on data

  • Apply the similar formula in cell B17 for the S group students and you’ll get the value 100.
=($C$7/SUM($C$4:$C$7)*100)+$B$16

arranging values

  • Copy the number of students in the P group in the first two cells of the P column.

arranging values

  • Where the values end in the P column (Row 11), copy the number of students of the Q group in the Q column for the two cells starting from Row 12.

arranging values

  • Copy the number of students for the rest of the groups in the other two columns.

excel bar chart width based on data

Read More: How to Make a Percentage Bar Graph in Excel


Step 2 – Insert a Stacked Area Chart and Format the Axis

We will plot the chart using the second dataset of the following figure.

excel bar chart width based on data

  • Select the values of the four columns – P, Q, R, S.
  • Go to the Insert, select the Insert Line or Area Chart drop-down and choose the Stacked Area option.

stacked area chart

We will get the following chart.

stacked area chart

  • Right-click on the X-axis and select the Select Data option.

excel bar chart width based on data

You will get the Select Data Source dialog box.

  • Select the Edit option on the Horizontal (Category) Axis Labels.

stacked area chart

The Axis label range dialog box will appear.

  • Select the range of the Number column in the Axis label range box and press OK.

stacked area chart

You will be taken to the Select Data Source dialog box again.

  • Press OK.

excel bar chart width based on data

  • Right-click on the X-axis and select the Format Axis option.

stacked area chart

  • On the Format Axis panel (it will appear on the right side of your Excel sheet) select the Date axis from the Axis Type option under Axis Options.

stacked area chart

The shape of the chart will be changed into bars of different widths.

  • Select the X-axis and press the Delete key.

stacked area chart

  • Delete the Legend and Y-axis.

excel bar chart width based on data

  • Delete the Gridlines.

stacked area chart

  • We will get the following bar chart without labels.

stacked area chart

Read More: How to Make a Bar Graph Comparing Two Sets of Data in Excel


Step 3 – Using a Formula to Create Labels

We will create our custom labels for the bars in the Indicator column.

excel bar chart width based on data

  • Use the following formula in cell E4.
=B4&"("&C4&" "&"students)"

The Ampersand operator will join the value in cell B4 with bracket, space, the value of cell C4, and with the text students.

formula for labels

  • Press Enter and drag down the Fill Handle tool.

excel bar chart width based on data

We will get all of the labels for the bars in the chart in the Indicator column.

formula for labels

Read More: How to Show Number and Percentage in Excel Bar Chart


Step 4 – Adding the Labels to the Bar Chart Width Based on Data

We will add our created labels to each of the bars of this chart.

excel bar chart width based on data

  • Go to the Insert tab and select Shapes under Illustrations, then choose a shape. We selected a rectangular box.

add labels to bars

  • A plus icon will appear as the cursor.
  • Drag it to the right side and top down to create the rectangular box in the first bar.

add labels to bars

  • After entering the rectangular shape, select it.
  • Use the following formula in the Formula Bar.
=$E$4

The value in cell $E$4 will be linked in the box.

excel bar chart width based on data

We will get the label in the first bar, but we can change some options to make it more visible.

add labels to bars

  • Go to the Shape Format tab, select Shape Fill, and choose No Fill.

add labels to bars

  • To hide the outline of the box, go to the Shape Format tab and, under Shape Outline, select No Outline.

add labels to bars

  • Go to the Shape Format tab and the Text Fill drop-down, then choose your desired color. We selected the White color.

excel bar chart width based on data

We have changed the format of the label of our first bar.

add labels to bars

  • Add and change the format of the labels of the rest of the bar.

add labels to bars

  • Change the chart title to “Variation of Heights for different Number of Students”.

excel bar chart width based on data

Read More: How to Sort Bar Chart Without Sorting Data in Excel


Practice Section

We have provided a Practice section like below in each sheet on the right side so you can test the method.

practice


Download the Practice Workbook


Related Articles


<< Go Back to Excel Bar ChartExcel Charts | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Tanjima Hossain
Tanjima Hossain

TANJIMA HOSSAIN is a marine engineer who enjoys working with Excel and VBA programming. For her, programming is a handy, time-saving tool for managing data, files, and online tasks. She's skilled in Rhino3D, Maxsurf C++, MS Office, AutoCAD, and Excel & VBA, going beyond the basics. She holds a B.Sc. in Naval Architecture & Marine Engineering from BUET and is now a content developer. In this role, she creates tech-focused content centred around Excel and VBA. Apart from... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo