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.
December 2010 - Posts - Tip of the Week

Tip of the Week

December 2010 - Posts

  • Final Tip of 2010

    We are taking a one week hiatus from the Tip of the Week Blog during the holiday season. However, a great tip was just posted by one of our colleagues, Christof, and I would like to link to that this week:

    We will be back next week with an all new tip.

    Happy Holidays!

  • Implementing Custom Visualizations in TIBCO Spotfire

    There are a variety of methods for incorporating custom visualizations into TIBCO Spotfire. These methods all vary greatly in terms of functionality and interactivity as well as in difficulty to develop. In this post, we will look at the different methods.

    Static Output Visualization
    One of the simpler options for a custom visualization is to provide a static output graphic which is displayed either in a Text Area or as a Custom Visualization.  In earlier tips we have shown how to do this with Google Charts , Yahoo Finance, and also as output from S+ or R.


    The benefits of this approach are that you do not need to use the full C# SDK  to implement the solution (as that is very time consuming), and you have access to many different visualization options. The downside is that the solution is a static graphic which does not provide the same interaction as a built-in visualization.  In some cases, using the static graphic as a details visualization, as shown in this post, reduces the need for full interactivity.           

    Configure Existing Visualization
    Many requirements for a custom visualization can actually be handled by configuring a built-in visualization. It could be something like a Map Chart which we configure to show the human body, a subway map, a Wafer Map, or something similar, as shown in this post.  


    It could also be something like turning a Bar Chart into a Histogram, or a Scatter Plot into a Bubble Chart. You can create these visualizations by just modifying the properties on a built-in visualization type. This requires no programming or the use of the SDK. In situations where you will use this type of plot a lot, you can even wrap this using the SDK to create a new visualization entry in the menu structure. This is called a configured visualization and details are available here.

    Yet another option which falls into this category is to add images into a Table visualization as discussed in an earlier tip.


    Integrate Third Party Visualization Component
    If the requirements call for a fully interactive visualization, similar to the ones built into Spotfire, it will require you to use the SDK to build a custom visualization. This process  is more involved, but details are available on our STN website on how to implement this.  If you have access to an already existing chart component or widget, and it is .NET/C# compatible, you can create a custom extension which integrates this component.  

    Two such visualizations components are Chart FX and Zed Graph. When integrating these components, you get all the built in features they offer including any marking, properties dialogs, etc… and you can hook it up to the Spotfire data model to support marking and filtering.


    Build Visualization from scratch
    The final possibility is to build a custom visualization from scratch using the .NET drawing capabilities. This could be a graphical visualization or a text-based visualization.  This is the most involved and complex solution, but has been done in many situations. In fact, the Spotfire Network Visualization add-on was built using this design pattern as well as visualizations created by some of our partners.


    The following table reviews the various methods we have discussed.




    Implementing custom visualizations can be done in many different ways, from a fairly static output graphic, which is actually what many requests really are, to a fully-fledged, built-in, “Spotfire plot”, with all the related interactivity.

    Usually requirements for custom visualizations involve specific context, which means that they most likely do not need to be generalized the same as a built-in visualization is. The first couple options listed in the table above are good approaches to solve the requirements for these very specific visualization types. If the requirement is more for a platform visualization that can be used in a variety of contexts, the last two options would be the best approach.

    If you are interested in implementing any of the visualizations listed in this tip, consider taking our  Authoring Bootcamp, our Advanced Extension training course,  or hiring Professional Services.

  • Writing Calculations, Annotations, and other values back to the Database

    In general, Spotfire only reads data from underlying datasources and does not add, edit, delete or in any other way modify the original data.  However, there are a variety of use cases where you would want to writeback information to the underlying data source. It could be calculated values, annotations, or anything else which was added to your data table during your analysis session.

    There are variety of ways to accomplish a database writeback from within Spotfire, all with varying levels of complexity and efficiency. You can use an Information Link to writeback to a stored procedure, you can use the SDK to create a Custom Tool which performs the necessary steps, or you can utilize Property Controls and Script Controls to accomplish this.  This tip will discuss using Property Controls and Script Controls, and will writeback an entire column back into the database.

    First, we need to setup a Text Area. In this Text Area, we will setup two Property Controls. The first one will display a list of columns from your data table which you may want to writeback to the database (this assumes it is an entire column or columns that you want to writeback and not just specific values). The second control is an input field which allows the user to specify the name of the Column to be added or replaced in the database.



    Next, we need to create a Script Control.  This Script Control will take in two parameters; specifically the values from the properties listed above.


    The script will use code we discussed in an earlier tip to find records in the data table. It will search for two columns; the one specified to writeback to the database, and a primary key column used to match records in the database. In our solution, we hard code the key column, but this could be exposed as an additional property control. 

    The script will use the  DatabaseDataSource  class to communicate directly with the underlying database (in our example it is a SQL Server database).  

    The full script is shown below:

    from Spotfire.Dxp.Data.Import import DatabaseDataSource
    from Spotfire.Dxp.Data.Import import DatabaseDataSourceSettings
    from Spotfire.Dxp.Application.Visuals import TablePlot
    from Spotfire.Dxp.Application.Visuals import VisualTypeIdentifiers
    from Spotfire.Dxp.Data import IndexSet
    from Spotfire.Dxp.Data import RowSelection
    from Spotfire.Dxp.Data import DataValueCursor
    from Spotfire.Dxp.Data import DataSelection
    from Spotfire.Dxp.Data import DataPropertyClass

    rowCount = Document.ActiveDataTableReference.RowCount
    rowsToInclude = IndexSet(rowCount,True)

    #Get a cursor to the two columns we want to use. cursor1 is for the key column and cursor2 is for the column selected by the user input

    cursor1 = DataValueCursor.Create[int](Document.ActiveDataTableReference.Columns["ProductID"])
    cursor2 = DataValueCursor.CreateFormatted(Document.ActiveDataTableReference.Columns[whichCol])

    #The following section will add a column to the database table using the name specified by the user. This assumes a column with this name does not already exist.

    sqlCommand = "ALTER TABLE Products ADD " + colName + " varchar(50);"
    dbsettings = DatabaseDataSourceSettings( "System.Data.SqlClient",
    ds = DatabaseDataSource(dbsettings)
    newDataTable = Document.Data.Tables.Add("temp",ds)

    #The following section will update the specified column in the database using the key column in the where clause
    for  row in  Document.ActiveDataTableReference.GetRows(rowsToInclude,cursor1,cursor2):
       value1 = cursor1.CurrentValue
       value2 = cursor2.CurrentValue
       sqlStr = sqlStr +  "UPDATE Products SET " + colName + "='" + value2 + "' WHERE (ProductID=" + str(value1)  + ");"

    sqlCommand = "UPDATE Products "  + sqlStr + ";"
    dbsettings = DatabaseDataSourceSettings( "System.Data.SqlClient",
    ds = DatabaseDataSource(dbsettings)
    newDataTable = Document.Data.Tables.Add("temp",ds)


    Once the solution is implemented, and the user clicks on the script button from within the Text Area, the correct information is written back to the database.

    This solution works well for something very quick and for small datasets, but is not recommended for production on large scale analysis files with lots of data. This is because it requires a connection to to the database from each client directly, it exposes the user credentials in the script as clear text, and the code is written in a scripted language, so performance on large data tables would be less than optimal.

    For a more efficient and production-ready solution, you should use the SDK to create a Custom Tool which utilizes compiled C# code. If you are interested in learning more about how to do this, or even having this solution built for you , please contact our Professional Services organization or consider attending our Developer Bootcamp training course.

  • Applying a Line Fit to Only One Set of Data When Using Multiple Columns on an Axes

    Suppose you have a chart similar to the one shown below, where you have multiple columns on the Y-Axis and you draw a line fit for each column on that axis? What if you only want to apply the line fit to one set of data, like Column 1, but still show both Column 1 and Column 2 on the chart?

    It is possible to do this, and it requires a couple steps.

    First, we should temporarily remove the Column from the axes that we do not want to draw the line for (in this example we remove Column 2)



    We then go into the chart’s property dialog and select ‘ Update manually’


    We then put Column 2 back on the on the Y-Axis.

    Once you do that, the final product will be that we have a line fit for Column 1 but not for Column 2.

     Interested in learning more about how to maximize your use of Spotfire? Consider taking our Essentials courses, or our authoring bootcamp. Our courses are offered onsite, regionally, or using our blended training model. Interested in blended training? Take a look at a sample topic from one of our courses, by clicking on this following link and then logging in as a guest.


Other Spotfire Blogs

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