The following snippets are examples of how to modify the statistics shown on a table using Table JavaScript via a custom rule.
Technical details
Not all statistics are available on all types of tables. The ones that you can use in the snippets below are listed in the Statistics - Cells, Below, Right lists when right clicking on a table. You can also use the following snippet to see which statistics are available via a log message:
log(table.availableStatistics);
Add a statistic
Automatically adds the Average to any table (that has this as a possible Statistics in its cells).
if (table.availableStatistics.indexOf('Average') != -1) { // If Average is available on this table
var stats = table.statistics; // Get the existing statistics on the table (selected by the context menu).
if (stats.indexOf('Average') == -1) { // If Average is not already selected
stats.push('Average'); // Add Average.
table.statistics = stats; // Use our new list as the statistics.
}
}
Change a statistic
// This changes a table's statistics to show % and n. table.cellStatistics = ['%', 'n']
See also
- Table JavaScript and Plot JavaScript for an explanation of how to run this code.
- Table JavaScript and Plot JavaScript Reference for technical information.
- Table JavaScript and Plot JavaScript Examples Library for other examples.
- JavaScript for information about the JavaScript programming language.
- QScript for tools for automating projects using JavaScript.
- JavaScript Variables for detail on how to create new variables using JavaScript.