Making Variable Bar Graphs in InDesign with Data Merge

If I told you that InDesign has offered the ability to make variable bar graphs since CS2 without the use of a plug-in, special font, or GREP style, would you believe me? It’s true! All you need is an Excel formula, Data Merge, and a character style. Intrigued? Read on for all the details of how I came up with the method and how it works.

Backstory: Experimenting with GREP Styles for Variable Bar Graphs

Regular CreativePro readers may be familiar with my efforts to create variable bar graphs in InDesign without using a third-party plug-in or the font FF Chartwell Bars.

  • The first version worked using a series of 50 GREP styles within a paragraph style.
  • The second version applied the same principle with fewer GREP styles.
  • The third version used a method similar to the second version, but with a script to automate the process of creating the GREP codes.
  • The fourth version was an experiment with an Excel formula to make the bar value into a binary number. The idea worked but it wasn’t any more practical than previous versions.

While they did work to create variable bar graphs using GREP styles, I wasn’t fully satisfied with these solutions for a few reasons. First, no one wants to hand-code complicated GREP styles every time they need to create a variable bar graph. The script definitely helped speed things up, but a critical roadblock still remained: GREP styles don’t work in text variables. The content in a text variable isn’t “real” text. Instead, it acts like a single special character that represents the entire text block. So, you can’t have mixed text formatting inside a text variable. If you’d like to encourage Adobe to address this issue there’s a long-standing feature request you can vote for over at the InDesign UserVoice site. But in the meantime, values represented as text variables can’t use the GREP graph technique.

Roman Numerals to the Rescue?

I contemplated a fifth GREP version that employed a different counting method, using Roman numerals. Initially this seemed like a workable idea. You can represent any number with various combinations of the seven Roman numerals (I, V, X, L, C, D, and M). So you’d need at least seven GREP codes. The trouble was that some Roman numerals such as IV (4) and IX (9) would display incorrectly unless you employed further GREP codes to deal with them. And even though you can convert Base-10 numbers to Roman numerals in Excel using the formula =ROMAN(), I felt that the solution was still too complicated.

But then I it occurred to me: What if I just took the number that I wanted shown as a bar graph, and used an Excel formula to transform it into an equal string of Roman Is? For example, 14 would become IIIIIIIIIIIIII. Furthermore, I realized that I didn’t have to use a Roman I. It could be any character, preferably one that I would be unlikely to type by mistake. I settled on the pipe symbol, | (the character above the backslash key on your keyboard).

At Last, GREP-free Solution!

Eventually, I realized that I could accomplish what I wanted without using GREP at all. For this new technique, I started by using the Excel formula for repeat, REPT(). I made two-column graph in Excel. The first column contained the actual data, and the next column contained the value =REPT(“|”,A2) which tells Excel to take the whole number in cell A2 and replace it with the same number of pipe symbols.

Illustration of the Repeat function in Excel

The formula worked. But I knew that this new column would be unwieldy whenever it contained large numbers, unless I formatted the text to make it smaller. So, I selected the column and changed the font size to 3 pt.

Resizing a large amount of data in Excel to fit in a small cell

From here, I exported the text from Excel as UTF-16 Unicode Text so InDesign could use it in a data merge operation.

Saving an Excel document in UTF-16 format

In my InDesign test file, I selected the text file as my data source and set up the placeholders.

A data merge template in Adobe InDesign for making variable bar graphs

In the Data Merge panel, I turned Preview on and I got my line of pipe symbols.

The result of a data merge in Adobe InDesign for making variable bar graphs

Then, I turned these symbols into a bar graph by applying a character style with the following options:

  • A fixed-width font, such as Courier Regular
  • A reduced Horizontal Scale to fit the space where the graph appears. In this instance I determined the Horizontal Scale had to be 39.4%.
  • A fill of [None]
  • An underline to create the bars themselves. I set the Weight to 13 pt, Offset to -4 pt, and the Color 100% Cyan.

Character style for creating variable bar graphs in Adobe InDesign

With the character style applied, the pipes disappeared and in their place was a bar that accurately represented the data.

Better Than a GREP Bar Graph

This technique offers a few advantages over the GREP methods.

  • Because the character style is only applied to the pipe characters, you can type elsewhere on the same line as the bar and get regular text.

  • You can make a stacked bar graph by creating variations of the character style with different colors applied to the underline.

  • It works in other programs. You can apply the same idea in Affinity Publisher, Quark XPress, Corel Draw, Microsoft Word, and potentially any other program that allows you to perform a data merge, and control the appearance of an underline, highlight, or strikethrough to the point where it resembles a bar graph.
Variable Bar Graph in Affinity Publisher

Variable Bar Graph in Affinity Publisher

More Than Just Bar Graphs

While this is a technique to create a bar graph, it has other potential uses. For example, if you set the color of the underline to [None], you have a variable “push-stick” that you can use to do the following:

The Best Technique, Bar None

So there you have it: variable bar graphs in InDesign without using plug-ins, GREP, or special fonts. This technique opens up new possibilities in Data Merge that I hope will inspire you to add single or stacked bar graphs to your variable data campaigns.

A prepress operator and graphic designer for a South Australian commercial printer, with close to 20 years of experience in the trade. He is also a regular contributor to this site and InDesign Magazine, and hosts his own prepress blog "Colecandoo".