Spotfire® Web Client User Guide

Adding actions performed when clicking on visualization items

Actions can be defined so that something happens when you click a dynamic item in a graphical table or a text area, or when clicking a tile in a KPI chart. The actions can open Spotfire tools that work on the range of filtered or marked data, apply bookmarks, or navigate to a certain page or visualization in the analysis; the same things that are available for action controls in a text area. It is also possible to add your own custom actions using scripts, or to refresh data function calculations.

About this task

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

Before you begin

Adding actions can only be done using the installed client.

Procedure

  1. In the visualization properties/settings for the visualization item (sparkline, calculated value, icon, bullet graph or KPI) to update, locate Actions.
  2. Select Perform action on click.
  3. Click Settings.
  4. In the Action Settings dialog, select the type of action to add: Actions, Script or Data Function.
  5. Type a Description for the action.
    This text can be shown in the tooltip when hovering with the mouse pointer over the item connected to the action. By typing a good description you can help other users understand what will happen when clicking on the item. For example, you can write "Go to page 2", "Refresh the calculation", or similar.

Configure details visualization

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.

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 configured to show all states on the Rows axis and two dynamic items of the type calculated value have been added, showing the sum of sales and the sum of cost, respectively:

Another visualization, a line chart, has been configured 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 show 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 defines what to show on the Y-axis and automatically limits the line chart by a boolean expression set to show data for the state of the clicked row in the graphical table only. The title of the details visualization is also updated by the same script:

  1. From the visualization properties, open the Calculated Value Settings dialog for the first column, "Sales", (on the Axes page) and go to the Actions section.
  2. Select Perform action on click.
  3. Click Settings.
  4. Click Script.
  5. Click Add > New script.
  6. In the New Script dialog, 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.
    Note: The example script assumes that a column called "State" is available in the data table.
  9. Next to Script parameters, click Add.
  10. In the Add Script Parameter dialog, 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 + "\""