Tip of the Week

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.

Comments

 

Kevin Hanegan said:

Someone asked for the code so they can copy and paste it...it is listed below:

# Draws a boxplot from the input table.

plotToPNGFile <- function(file, plotExpression, width, height) {

       java.graph(file=file, width=width, height=height, format="PNG")

       dc <- dev.cur() # id of graphics device just opened

       on.exit(dev.off(dc)) # make sure device is closed, even if error in plotExpression

       plotExpression # evaluate by lazy evaluation

   }

plotToRawColumnInDataFrame <- function(plotExpression, width=500, height=400) {

       t <- tempfile()

       on.exit(unlink(t))

       plotToPNGFile(file=t, plotExpression, width=width, height=height)

       data.frame(r=readRaw(file(t, open="rb"), what=raw(file.info(t)$size)))

   }

plot.names <- names(tapply(yCol,xCol,sum))

plot.data <- tapply(yCol,xCol,sum)

plotImage <- plotToRawColumnInDataFrame(barplot(plot.data,names=plot.names,hori=T))

June 16, 2010 2:43 PM
 

FOREX RANGE BAR CHART RE-ENGAGEMENT FX TRADE | Currency Trading Exchange Guide said:

Pingback from  FOREX RANGE BAR CHART RE-ENGAGEMENT FX TRADE | Currency Trading Exchange Guide

June 21, 2010 11:06 PM
 

How To Use Bar Patterns For Trade Setups | Currency Trading Exchange Guide said:

Pingback from  How To Use Bar Patterns For Trade Setups | Currency Trading Exchange Guide

June 24, 2010 9:31 PM
 

Tip of the Week said:

In an earlier post , we discussed how to add Horizontal Bar Charts and other charts into TIBCO Spotfire

June 27, 2010 9:21 PM
 

Knowledge Base said:

In an earlier post , we discussed how to add Horizontal Bar Charts and other charts into TIBCO Spotfire

June 27, 2010 10:19 PM
 

kpetocz said:

I know about an other HB solution, but this is an enhancement for SPF

spotfire.hu/.../horizontal-bar-chart

August 1, 2010 7:05 PM
 

Tip of the Week said:

We have shown in earlier posts how to execute Data Functions from within Spotfire using TIBCO Spotfire

October 24, 2010 8:57 PM
 

Guillaume said:

Just to confirm, this is not doable with Spotfire only, right ?

I got a 'Failed to execute function call, There is no URL specified for TIBCO Spotfire Statistics Services.' when following the above...

December 20, 2010 9:49 AM
 

Kevin Hanegan said:

Correct Guillaume,

We are using TIBCO Spotfire Statistics Services to generate the horizontal bar chart and then pass it back into Spotfire, so you definitely cannot do it with just Spotfire.  There is another tip showing you how to use 3rd party components like Google Charts, which can accomplish something similar with just Spotfire.

Kevin

January 8, 2011 9:00 PM
 

uggkensington said:

http://www.uggkensingtons.org/

http://www.uggkensingtons.org/ugg-fox-fur-short-boots-5531-c-54.html | UGG Fox Fur Short Boots 5531

http://www.uggkensingtons.org/ugg-kensington-boots-5678-c-2.html | UGG Kensington Boots 5678

http://www.uggkensingtons.org/ugg-rainier-eskimo-boots-5189-c-85.html | UGG Rainier Eskimo Boots 5189

http://www.uggkensingtons.org/ugg-retro-cargo-boots-1895-c-3.html | UGG Retro Cargo Boots 1895

December 27, 2011 8:17 PM
 

uggskensingtonsale said:

www.uggskensingtonsale.org

www.uggskensingtonsale.orgugg-adirondack-boots-ii-c-6.html | UGG Adirondack Boots II

www.uggskensingtonsale.orgugg-adirondack-tall-boots-c-11.html | UGG Adirondack Tall Boots

www.uggskensingtonsale.orgugg-amberlee-boots-c-34.html | UGG Amberlee Boots

www.uggskensingtonsale.orgugg-annabelle-boots-c-35.html |

December 28, 2011 4:22 AM
 

uggretrocargosale said:

January 4, 2012 8:48 PM
 

benjaminb said:

Is there an equivalent but using R script ? Thanks

February 17, 2012 10:51 AM

Leave a Comment

(required) 
(optional)
(required) 
Submit

Syndication

Other Spotfire Blogs

Spotfire's interactive information visualization and analytic solutions give users a remarkable experience for quickly and easily querying data and reporting results for superior business intelligence. From portfolio management and customer retention programs to key processes such as CRM, marketing, research, bioinformatics, yield and asset management and design for manufacturing, enterprises around the world rely on Spotfire's business analytics software to improve operational performance.

©Copyright 2000-2011 TIBCO Software Inc | Privacy Policy | Terms of Use I Blog I Contact Us I Content Center