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.
Workarounds
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
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.
Wow. This is seriously cool Colin! Well done.
Download working? Gert
I’m also having trouble with the download
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.
Colin ask folks at InDesignSecret to Zip the script.
Nice one.
I got a full page of letters no script in the download:
@JSXBIN@[email protected]@MyBbyBnABMgdbyBnABMiEbyBn0ACOiFbyiGn0ABJiGnASzG2DhX2lFE2kfE2MhX2JhX2kaEBAEXzEjJjUjFjNCfXzPjQjBjSjBjHjSjBjQjIiTjUjZjMjFjTDfjzH2nKB2nLB2ZO2UHmS2ShW2leEEfRBVzKlamamV2kYmX2LB2HJ2DFmFnLiXFfEffnftACzChBhdGEXCfXDfVzC2nCnZ2kThbHfDRBVFfEffnnbbiIn0ADJiInASzI2OV2CV2RW2VC2YS2UOmC2kXEIBXzVjBjQjQjMjJjFjEiQjBjSjBjHjSjBjQjIiTjUjZjMjFJfXzMjUjFjYjUiEjFjGjBjVjMjUjTKfVHfDnftJiJnASzLjYjYnNiSiEiGnajS2GhX2lZE2KlBLCWzGiPjCjKjFjDjUMCzEjOjBjNjFNVFfEzHjCjBjTjFjEiPjOOVIfBnftJiKnASBAEXzDjBjEjEPfXDfjEfRBVLfCffnftZiMnAVBf0AFL4C0AiAH40BhAF4B0AhAB40BiAI4B0AiACDAzWjDjIjFjDjLiQjBjSjBjTjUjZjMjFifjEjFjGjBjVjMjUQAiNhRJgenASzFnK2UhW2EhW2nIBlVRAE
Amazing! Fabulous trick with GREP even more easy to do now…
Nice! It doesn’t seem to support fractions, though (like 50.5, etc.).
Yes, that is a limitation. The first article (https://creativepro.com/grep-style-bar-graphs-for-data-merge.php) mentions it briefly. I believe the Chartwell typeface also has a similar limitation.
Nice one, Colin!
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?
Thanks!
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!
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.