The Spotfire Community is moving to TIBCOmmunity and this forum location has closed. During the transition, you can still search the old forums but posting has been disabled. We encourage you to pick up the discussion at the new Spotfire community on TIBCOmmunity.
April 2010 - Posts - Tip of the Week

Tip of the Week

April 2010 - Posts

  • Using Property Controls to Filter Data

    Property Controls are very useful for allowing consumers to affect values in an analysis file, like what to display on a given axis, but they do not work directly with marking or filtering. However, it is possible to hook property controls up to affect filtering by using an expression. Below we will explain how to do this for a couple different scenarios.

    Assume you have a data table which contains sales data about stores in 4 different locations: Boston, Seattle, New York, and Los Angeles.
    You may want to display a Line Chart which displays the count of customers’ most recent purchases by month. NOTE: It can in fact be any chart, not just a Line Chart, but we will just use this for the sake of our article.


    Next, we will need to create a Property Control. For this, we may want to create a multi-select List Box which contains values for our ‘Store Location’ column.

    Then, we need to create our intermediary expression. This part gets a bit tricky so we will break it down into small steps.  What we want to do is have the output of the expression be either 'Yes' or 'No'. Yes, if the value is selected in the property control and no if it is not. 

    We will need to use the find function to search to see if a value from the Property exists in the Store Location column. If it does, we output 'Yes', and if it does not ,we output 'No'.
    If we only cared about single value selections from the Property Control, then it would be an easier expression, and we could do the following:

        if(find([Store Location],'${whichStore}')>0,"Yes", "No" )

    where ${whichStore} refers to the Property Control we just created.

    If you want to allow the user to select multiple values in the Property Control, you need to extend your expression by using the $map preprocessor. Replacing ${whichStore} with $map("'${whichStore}'", "&")  will give us the desired result.  This is telling us to create a string where all the values in the whichStore Property Control are concatenated using the & character. So, if the Property Control has the values 'Boston' and 'New York' selected, the output from the map preprocessor would be “Boston & New York”. 

    The find function will then search through each row in the data table, take the current row’s value for Store Location, and see if it finds it inside the Property Control string (i.e. ‘Boston & New York’).

    Below you will see we added this expression into a new calculated column called ‘Store Location Property Control’.

     Now that the column is created, we can adjust its filter to only show Yes.

    The end result allows us to hide the Filter Panel and expose a single filter , created as a Property Control, via a text area. This will allow us to control filtering for the entire Filtering Scheme, including all Visualizations in all Pages attached to it. Of course, you can setup the Filtering Scheme to only work for a single page if desired as well.

    Using Script Controls to do the same thing
    Keep in mind it is also possible to accomplish a similar result using Script Controls. The downside of using Script Controls are that you need to create a button or link that will perform the filtering, there is no way to trigger it automatically when the Property Control is updated. The upside of using Script Controls are that you have access to more features in the User Interface to manipulate. For example you may want to update the Visualizations’ title to describe which values are selected. 

    If we did this, we would not use the calculated column, rather we would send the property control values in as input to the Script Control, and we would use them to check or uncheck filters. Below is a screen shot of this script, where the property control values get sent in as a parameter called strSelection and the visualization we wish to update the title on gets sent in as a parameter called visual.


    Property Controls to Filter a Single Visualization

    What if you want to only control a single visualization and not all the visualizations in a Filtering Scheme?  Then you would want to add a similar expression as a custom expression into the visualization, rather than as a calculated column.   Let’s take the same Line Chart as an example. The X-Axis shows us the Month of the most recent purchase, and the Y-Axis shows us the count of customers. Since the Y-Axis is showing us a number, we can replace this axis to show us the number of rows (customers), from the selected Store Locations (from our Property Control).  The expression required to do this on the Y-Axis is:

      Sum(if(find([Store Location],$map("'${whichStore}'", "&"))>0,1, 0 ))

    We had to replace the Count aggregation with Sum, and we had to replace the 'Yes' and 'No' with 1 and 0.

  • Using Built-in Actions vs Script Controls

    In TIBCO Spotfire version 3.1, there are multiple ways to expose additional controls to a consumer via the Spotfire Web Player. We have already discussed Property Controls as well as Script Controls.  In addition to these two features, there are also some built-in actions.

    When inserting links into TIBCO Spotfire versions 2.0 – 3.0, you had the ability to use some built-in functions as shown below. However, these functions would not appear in the Web Player.  Instead, the consumer would see a broken link.



    In TIBCO Spotfire 3.1, when inserting an Action Control, the same functions, as well as some additional ones are there.  All of these functions now will work in the Web Player.  There is no need to create a script, for example, to reset all filters or visible filters, as this is done as a function.


    Where you would need to use a script is if you wanted to do something that was similar, but not exactly the same as on this list. For example, if you only wanted to reset the filters for a specific table, you could expose the table names as a property control and then send the selected value as an input parameter to your script, which would then loop through all columns in the inputted table and reset their respective filters.  The code for such a script is shown below:


    from Spotfire.Dxp.Application import Filters as filters

    myPanel = Document.ActivePageReference.FilterPanel


    #whichTable below is a string input parameter which is connected to a Property

    for col in Document.Data.Tables.Item[whichTable].Columns:

        myFilter= myPanel.TableGroups[0].GetFilter(col.Name)



    This post also marks our 6 month anniversary. We have been doing weekly posts since mid October. Tell us what you think? We plan on continuing to do tip of the weeks, but we would like to hear from you to know if you are reading and enjoying them and if you have other categories (more API ones, more admin ones, less technical ones, more technical ones, etc...) you'd like us to write tips on. Thanks!
  • Using Script Controls to Automate Visualization Properties

    In a previous Tip of the Week, we introduced you to Script Controls.  Since that tip, interest in Script Controls has grown exponentially.  As a result, we are presenting another tip which shows you the power of Script Controls to expose visualization properties to a Business User. These tasks can be done  by a Business Analyst or Author inside TIBCO Spotfire Professional , but if you want to expose these tasks to Business Users in the Web Player, this is where Script Controls come in.


    In the first example, we will create a Script which will allow a Business User to toggle whether to ‘Sort bars by height’.  Below is the script for this task:

    from Spotfire.Dxp.Application.Visuals import BarChart


    for  vis in Application.Document.ActivePageReference.Visuals:

       if  vis.Title == "Bar Chart":

           if vis.As[BarChart]().SortedBars == True:

              vis.As[BarChart]().SortedBars = False


              vis.As[BarChart]().SortedBars = True



    In the next example, we will create a Script which will allow a Business User to toggle a Bar Chart’s Stack Mode from Stacked to 100% Stacked. Below is the script for this task:


    import Spotfire.Dxp.Application.Visuals.StackMode as stackMode

    from Spotfire.Dxp.Application.Visuals import BarChart


    for  vis in Application.Document.ActivePageReference.Visuals:

       if  vis.Title == "Bar Chart":

           if vis.As[BarChart]().StackMode == stackMode.Stack:

              vis.As[BarChart]().StackMode = stackMode.Stack100Percent


              vis.As[BarChart]().StackMode = stackMode.Stack

    If you are interested in learning more about Script Controls, we just launched our full day course SP232 - TIBCO Spotfire Automation APIs using IronPython. This course covers how to create Script Controls, introduces you to syntax and semantics of the IronPython language, and also walks you through the Spotfire Automation (Client) APIs. View details about the course and schedule at the following link. 


    Also, we are launching a new feature of the Community: a poll, which will serve to help us gather information in order to improve the Community, our product, our training, etc... Please check it out. New polls will most likely be created every couple weeks or monthly.


  • Creating Gaussian Curves to display Normal Distribution

    Gaussian curves are widely used in statistics where they describe the normal distributions of your data.  In TIBCO Spotfire version 3.1, we are now able to draw a Gaussian curve.  

    Let’s assume we have a Bar Chart that acts as a histogram, displaying the count of each value in the Data Table.


    We can then add a ‘Gaussian Curve Fit’ via the Lines & Curves Properties dialog.



    In the resulting Gaussian Curve Fit Properties dialog, we can manually set the desired Position, Width, and Amplitude, or we can leave it as Automatic, and those values will be calculated based off the data in the plot.

    When you are finished with the settings, you will see a Gaussian Curve (Normal Curve) applied in your Bar Chart.


    Other than this, you can also create a normal curve using a custom curve fit, but this also requires additional calculated columns in your Data Table, and then the graph would not show a histogram of your data as above, but rather a distribution based off standard deviations.  This graph, shown below, would make a great details visualization.


Other Spotfire Blogs

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