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.
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
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.