Using Formatting Rules With ExtendScript

During placement of a Formatting Rule ‘Post Processing’ can be used to modify the contents of the Formatting Rule.

In this example, a script creates a pie chart based on the values in a data source. This requires the scripting module as objects are passed to represent the data which is assigned to to the rule.

Example Data

olympics.csv

The next thing is to create a basic formatting rule with a single circle. This will be the base for the pie chart.

In the “Post Processing” section of the Formatting Rule, “ExtendScript” needs to chosen. Then the following code creates the Pie Chart.

The script is passed arguments. The first argument is the Formatting Rule frame, the second is an array of Record objects. The third member, unused in this example is a Datasource object.

The script that creates the pie is relatively complex, so the Formatting Rule includes it as an external file and calls it, passing an array of values to populate the chart with. The entire script can be downloaded here – PieGraphFR.jsx

Scripts are located in the users Scripts Folder, or in the data sources Scripts folder.

This script duplicates the original frame and creates segments for each element of the pie. EasyCatalog manages the creation and deletion of any frames by the script, which are then combined into the Formatting Rule. It’s also possible for this script to delete the rule completely.

The following example creates a table with a row and a link for the “Country”. The Formatting Rule is simply a text box and the script is used to created the content: