|
ABC ~ All
'Bout Computers
The Online Web-azine for Computer
Enthusiasts
-- brought to you by

contents page for this issue
Highlighting a Single Data
Point in an Excel Chart
~~Ray Blake,
GR Business Process Solutions
Excel’s charting tools are quite
comprehensive, but I’ve written before (see my archived articles) about
some notable omissions in functionality. One of those is less control
than a user might like over the colour of individual data points. It is
possible to set the colour for an entire data series, or to set the
colour to vary by point. The charts below illustrate these options:

This choice is controlled through the
Format Data Series dialog, as below:

At first, I thought I’d be able to
make progress with VBA, but it is not possible to change the colour of a
single data point, even from VBA code, when you want the colour to
change based on the data that produces that column.
It’s time perhaps to explain why I
wanted to be able to highlight just one point. Let’s do it by looking at
the data on which the example charts above are based.

It concerns a multiple choice test
based on 4 questions, each with 4 possible answers (A, B, C, D) only one
of which is correct. Column C indicates which option is correct
and columns D-G show what percentage of the test candidates selected
each option.
When
charting these numbers, I wanted a way of highlighting which option was
the right answer. Consider the chart we saw at the top of this article,
shown again to the left.
It relates to question 1 in the data
table, of course, and the right answer is B.
The data source for this table is D3:G4, which includes both the axis
labels in row 3 and the actual chart values for the series in row 4. The
other charts for questions 2-4 are based on ranges which include rows 3
for the axis labels and respectively 5, 6 and 7 for the series data.
Given that B is the right answer, the
chart shows a test question performing very well, for a number of
reasons. It shows:
-
The majority of candidates are
getting it right (so it’s not too hard)
-
Not all candidates are getting it
right (so it’s not too easy)
-
Candidates are choosing all 3 of
the wrong answers, which we call ‘distractors’ (so all the
distractors are to some extent credible and candidates cannot get
the answer right just by eliminating obviously false alternatives.)
It is easy to come to these
conclusions simply from the chart, but only if you know the right answer
is B. Look at the chart again and consider how the story it tells is
different if the right answer were actually A.
Hopefully, you can see why I was so
keen to highlight on the chart one data point.
A method which my business partner,
Graham Barrow, suggested is to provide a text key. A little-known
ability of Excel charts is to link the title or other text box in the
chart to an Excel cell value. You can’t actually get it to calculate a
formula, but you can get it to show the content of a given cell. Here is
how I implemented this idea on my chart.

What looks like a single text box at
the top of the chart is actually 2. The one on the right is the title
box and here simply says ‘B’. It’s linked to cell C4, so if the data
changes, it will change too. Immediately to the left is another
text box which just contains the text "Correct answer:"
To link the right hand text box to
the cell, I simply went to the chart options and said I wanted title
text (I typed a few letters of nonsense into the box, just to get
something on the chart.)

Then, with the title box selected, I
entered the cell reference in the formula bar:

After that, it was simply a matter of
inserting another text box in the chart area, and matching its font and
style to the chart title box.
This was a good solution, and in a mono printing situation would
probably be preferable to varying the bar colour in any case. But I just
couldn’t walk away from the challenge of recolouring just a single data
point, so I worked on and eventually cracked the problem.
It actually turned out to be very
easy, although very sneaky, and required no VBA at all.
Here’s what I did.
First, I realised I would need to
extend the data table to create a second data series for each line. I
did this by inserting a row below each line of data, thus:

The formula I entered in cell D5 was:
=IF(D$3=$C4,D4,0)
I dragged this across cells E5, F5 and G5. The result is shown below:

You can see in row 5 that the value
for the right answer is carried down and all the others are given as
zero. This row of cells will be a second series which we will chart on
top of the first.
Through setting the references as relative in the formula (all those $
signs are carefully placed!) I was able to copy and paste this single
formula into all the new cells without amendment, not only in Row 5, but
also in the 3 new rows below. Note that I can hide these rows if I want
to, or turn the text colour to white. It won’t affect this chart
technique if I do.
Now, I turned to the chart to make
some amendments.
First, I selected my original chart
and viewed its source data (available from the right-click menu of the
chart area). Currently, you’ll recall that the source data is based on
the range D3:G4. Row 3 contains the axis labels – A, B, C and D. Row 4
contains the data we want to chart – how many candidates chose each
option.
Here is the source data dialog as it stood initially:

What I did was to extend the data
range so as to include the third row, row 5:

Notice that the second series is now
showing in the preview, but that because 3 of the four values are zero,
only the correct option has any bar showing. I clicked OK.
Then, I double-clicked on any of the
data bars to get this dialog:
Note that the ‘overlap’ value is set to zero. I’m going to change this.

Now look what happens when I increase
the Overlap to 100%:

And that’s it!
Returning to my worksheet, I appeared now to have done the impossible:
created a chart with just a single data point highlighted a different
colour. Of course, I created new charts for the other 3 data sets, too.
Look at the four of them below, and see of you agree that colouring the
right answer makes a visual analysis easier:

Ray Blake lives in England and spent 15 years training people in the
financial services industry there. He had always used PCs in his work, and
gradually realized he might make a career out of them. He and his business
partner set up GR Business Process Solutions (www.grbps.com)
which specializes in innovative IT to support knowledge testing and skills
assessment. Although he spends a lot of time these days developing in VB and
Access, Excel remains his favorite development tool, because, as he says,
'It can do everything; there's no computer application you can think of that
you couldn't develop in Excel.'
|