Thanks for coming to, the world's #1 resource for all things InDesign!

A Script for Making Bar Graphs with GREP

In late 2016, I demonstrated a technique to create bar graphs in InDesign using only a fixed-width font such as Courier New and GREP styles. The article detailed the GREP and character styles required to change a number from 0 to 1999 into a bar graph.

The Dilemma

After writing that article, it was obvious that creating all 29 character and GREP styles required for the technique to work was a boring chore, and not something that anyone would do if a bar graph was rarely required. While the technique worked, a better way of implementing it was required.


The obvious answer should be CC Libraries, right? Once the styles are made and applied to text in a text frame, drag the text frame into a CC Library and it can be recalled easily. Sounds good, but this method has some drawbacks:

  • The expected limitations within CC libraries as written about previously.
  • CC Libraries can’t store object styles, so storing each paragraph style in its own object style isn’t an option.
  • If more colored bars are required, then duplicating existing paragraph styles to create the additional bars will need necessary.
  • It assumes that Creative Cloud is being used, and as the recent poll results show close to a quarter of poll respondents aren’t using it.

One option would be to create the styles once into a document, and then anytime a bar graph was required, recall the file and copy the styles from one file to another. Again, if bar graphs are not created regularly, this would require locating the file that contained the bar graph styles to copy, a task that is akin to finding a needle in a haystack.

Another option would be to create the styles with no documents open, so that the styles could remain on the user’s machine. Again, if bar graphs were rarely required, this would result in just under three dozen unnecessary character styles being added to any files that were created.

A Better Solution

Instead, a solution that is far more appropriate is to run a free script that I’ve made solely for the purpose of preparing the necessary styles in a document. Take the following example – seven values that I’d like to represent in a bar chart

GREP graph data

Instead of beginning the laborious task of creating all of the character and GREP styles, the grepstylegraphs script can be downloaded from here. Instructions on installing this (and most javascripts) can be found here.

With the script now installed, it can be run from the Scripts panel. A dialog box appears:

Given that there are seven values, having seven bars seems appropriate, so seven is selected from the dropdown menu and OK is clicked.

An alert dialog now appears, informing you that the styles are made and how the styles can be applied.

So now I’d like to apply the styles to this script. Let’s have a look at what the script has added to the styles panels:

The script has added all appropriate object, paragraph and character styles, as well as unique swatches (with color values determined at random) for each graph. In this example, the figures are in a text frame that can have the object style applied to it.

The textframe now has the GREP style graphs applied.

Alternately, if any text frames are selected when the script is run, a warning dialog box appears stating that the selected text frames will have the GREP Graph style applied, and provides an option to proceed.

The script only needs to be run once to create the styles. Once run, the object or paragraph styles can then be used to apply the GREP styles to numbers throughout a document.

For more complicated graphs, try Chartwell

While this script provides a solution for creating bar graphs from live text, if more complicated live-text graphs are required, then consider the Chartwell typeface from the FontFont foundry. Check out a previous article about the Chartwell typeface here.

Colin Flashman

Colin Flashman

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".
Colin Flashman

Latest posts by Colin Flashman (see all)

  • - November 30, -0001
Related Articles

14 Comments on “A Script for Making Bar Graphs with GREP

  1. The script works, but instead of clicking on the link and expecting it to go to a save location, RIGHT-click on the link and select SAVE AS and then choose the file location.

  2. I got a full page of letters no script in the download:


  3. When I try to run the script, I get a javascript error:

    Error Number: 15875
    Error String: The requested font family is not available

    What font do I need for this to work?


    • Nevermind – I went back and read the article again and saw the font info at the beginning.

      This is a great script! Thanks for sharing!

  4. Given that there are seven values, having seven bars seems appropriate, so seven is selected from the dropdown menu and OK is clicked.If more colored bars are required, then duplicating existing paragraph styles to create the additional bars will need necessary.

Leave a Reply

Your email address will not be published. Required fields are marked *