Horizontal Bar Charts in TIBCO Spotfire through TIBCO Spotfire Statistics Services


Ever want to use a  Horizontal Bar Chart in TIBCO Spotfire?  Sure, you can use the SDK to build a custom visualization, but that is alot of overhead.  With the ability to execute S+ and R from within the Spotfire platform, there is an easier way to accomplish this capability: using Data Functions. Ideally this should be setup as a detailed visualizations, but can be setup to be main visualizations as well.

First, you will need to register a Data Function using Tools > Register Data Functions from within TIBCO Spotfire Professional.  The Data Function will be an S+ Script , which will generate a Horizontal Bar Chart and output it as a png image. The script is shown below.


 
The script will take in two input parameters. Both are required and will be of type Column.  These will be the columns we want to display on the X and Y axis of the Horizontal Bar Chart.


The script will output one parameter. It will be of type Value. This will be the Bar Chart , being returned as a PNG image.


 

Once we have created the S+ Script, we now can include it in a given Spotfire Analysis File using the Data Functions tool from Tools > Data Functions.  Here, we must map the expected input parameters to values from the analysis document.
In our case, the current analysis document has the following columns:


 
We would like to have the Bar Chart display the 'Total Amount of Purchases' for each 'Store Location'.  To generate this , we need to send in both of those columns as the input to the script.  First, we send in the Store Location column. Since we want to have this be a details visualization, we select to only send in marked rows to the script.


 
Next, we send in the 'Total Amount of Purchases' column. However, this is a currency column in Spotfire and S+ does not support currency data types. To resolve this, we define the input as an expression instead of a column, and then create an expression that casts the 'Total Amount of Purchases' column to an integer.


 

For the output of the script, we want to attach the image being returned to a document property of type Binary.


 
Lastly we need to create a Property Control from within a Text Area to display the image.  For this we will pick a Label Property Type.


 

Once done, we see the finished product.  Mark records in the Scatter Plot and then a Horizontal Bar Chart will be displayed as a Details Visualization.

Everytime you update the marking, the Data Function will be re-executed and an updated Horizontal Bar Chart will be displayed. This works since we checked the 'Refresh function automatically' button.

Interested in learning more about Data Functions? Take our course specific for learning Data Functions for either S+ or R: TIBCO Spotfire Data Functions : Executing S+ and R code from TIBCO Spotfire. The course can be taken using our blended learning model for only $600 per person. Blended training gives you access to our online training portal to consume asynchronous materials including for 30 days. During those 30 days, you have access to an instructor to help answer any questions you may have.  When the 30 days are up, there is a live webinar typically lasting 2 hours to review concepts, do live demos, and also to answer any questions.  This model is well suited for adult learners as you can break up the learning over time to retain more and also have it fit into a busy schedule.