Most people know that Excel has a solid chart system that can draw variety of chart types ranging from simple pie chart to a more complex 3D Radar chart and for each chart types there are tens if not hundreds configuration options. Most people also know that these charts are auxiliary to the Excel worksheet itself. One can overlay a chart on top of a worksheet but one can not embed a chart into one of the cells. It usually looks like the following:
Note that the bar chart is somewhat disconnected from the source data and the chart is an overlay on top of the worksheet. Well, there are better options to do this…
The first way to embed a bar chart in a cell is the old way. It is really a workaround and it is by dynamically generating a string that will look like a chart. We can do that with the function REPT to repeat a character such as “|” and generate the needed bar. This is something I saw first at the following place:
Let’s assume that cell D2 contains a value and we want cell E2 to include a graphical representation of that value, then we can use the function:=REPT(“|”,D2)&” “&D2
Which means: Repeat the “|” character D2 times and at the end add the string representation of D2.
If we repeat that calculation for every cell in the D column we will have something like this:
I cheated a little bit as I used conditional formatting for the colors and used one of the narrow fonts like “Arial Narrow”.
Now let’s continue. Replace “|” with the character “g” but use the funky font Webdings. Also reduce the font size to 4 or so and we get something that looks closer to charts:
That is nice but we can do better. In Excel 2010 there is a new thing called Sparklines. I will talk about this next time…