Action Script Examples

Actions can be defined to be performed when clicking a dynamic item in a graphical table or a text area, or clicking a tile in a KPI chart. Below is an example of what you can do by setting up an IronPython script action on two dynamic items of the type calculated value in a graphical table.

Tip: See IronPython Scripting in TIBCO Spotfire on the TIBCO Community for many more examples as well as tutorials on using scripts in Spotfire.

Configure Details Visualization Example

This example uses a fictive data table containing sales and cost for a number of products in the different states of USA. The graphical table has been set up to show all states on the Rows axis and two dynamic items of the type calculated value have been added, displaying the sum of sales and the sum of cost, respectively:

Another visualization, a line chart, has been set up to show either the sum of sales or the sum of cost for the marked state in the graphical table over the time, thus displaying the details behind the total sum for each state. In contrast to a standard details visualization controlled by the marking, this visualization will display different data depending on which cell you click on; clicking in the Sales column will show the sales for that state and clicking in the cost column will show the cost.

This is done using an action script on the columns in the graphical table which sets what to show on the Y-axis and automatically limits the line chart by a boolean expression set to display data for the state of the clicked row in the graphical table only. The title of the details visualization is also updated by the script:

To add the action to the graphical table columns:

  1. Open the Calculated Value Settings dialog for the first column and go to the Actions page.

  2. Select the Perform action on click check box.

  3. Click Settings.

    Response: The Action Settings dialog is displayed, providing you with the same options as when inserting action controls in the text area.

  4. Go to the Script page.

  5. Click New.

  6. Type a Script name (for example, "Configure Details Visualization").

  7. Type a Description (for example, "Configures a visualization to show details of a graphical table cell.")

  8. Copy the script below and paste it into the Script field.

    Comment: Note that the example script assumes that a column called "State" is available in the data table.

  9. Click Add.

  10. Type the Name detailsVis, as expected by the script.

  11. Let the Type be a Visualization and select the line chart to use as the details visualization from the list.

  12. Click OK in all dialogs to close them.

  13. Add the defined script to the other column as well, to be able to show either Sales or Cost details in the line chart.


# This script is intended to be run as an action on a

# Calculated Value miniature visualization in a graphical

# table.


# It expects one Visualization argument, detailsVis, and

# it configures the specified visualization to show details

# for the clicked cell.


# When executed as an action in a graphical table,

# the variable Context is bound to an instance of

# MiniatureVisualizationActionContext (see API documentation).


from Spotfire.Dxp.Application.Visuals import VisualContent


# This script assumes that the row axis of the Graphical Table

# is configured with one column: State.


# Get the miniature visualization and the value of the row

# axis hierarchy (the state column) for the clicked cell:


clickedMiniVis = Context.Visualization

state = Context.HierarchyPathValues[0]


# Get the content of the visual that shall be configured to

# show details. Use the most general type so that the script

# works for all VisualContent classes that have a Y-axis

# property. This works well for a Line Chart, for instance.


vc = detailsVis.As[VisualContent]()


# Configure the Title and YAxis of the details visualization:

vc.YAxis.Expression = clickedMiniVis.ValueAxis.Expression

detailsVis.Title = clickedMiniVis.Title + " for " + state

# Limit the data of the details visualization to only use

# data for the selected state:


vc.Data.WhereClauseExpression = "State = \"" + state + "\""

See also:

IronPython Example Scripts