Jump to content
  • Selecting columns to display in a Table visualization via Property Control


    Automating operations in Spotfire® with scripting is immensely powerful. It can be used for anything from providing shortcuts to frequent operations to building extremely capable enterprise grade analytic applications.

    Introduction

    Automating operations in Spotfire® with scripting is immensely powerful. It can be used for anything from providing shortcuts to frequent operations to building extremely capable enterprise grade analytic applications.

    In the article we will see how you can enable end-users to change which columns to display in a table visualization. This may be useful when you need to use a single table to display different contents dependent on the user's current interest. There are two ways to change data table columns to display via property control.

    Method 1: Selecting one or multiple columns to display on a table visualization

    converted-file.png.53940146dae8d1cb9d6415ca1e13793a.png

     

    1. Create a Text area and add a Property Control of type List box (multiple select)
    2. In the Property Control setting:
      • Add a new Document Property of type String. Let's name it "columnSelection".
      • Set property value through "Column selection".
      • Click Select Columns... button and choose columns to include.
      • Now click Script... button and select "Execute the script selected below:" and click New.
      • Add script parameter of type Visualization and select your data table. Let's name it "tablePlot".
      • Paste-in the script below and click OK to close all settings.
      • You can now select columns to display using the List box (multiple select) Property Control.

    Script:

     #get columnSelection document property 
     from Spotfire.Dxp.Data import DataPropertyClass 
     selection = Document.Data.Properties.GetProperty(DataPropertyClass.Document, "columnSelection").Value  
     
     #apply column(s) selection to the table plot 
     from Spotfire.Dxp.Application.Visuals import * 
     tablePlot.As[TablePlot]().Columns.Clear() 
     tablePlot.As[TablePlot]().Columns.AddRange(selection)

    You can download the attached ColumnsSelection.dxp to see the property control in action.

    Method 2: Selecting a collection of columns to display on a table visualization


    converted-file.png.264c26449c8bdeb63b872bc7c194807b.png
     

    1. Create a Text area and add a Property Control of type List box or Drop-down list
    2. In the Property Control setting:
      1. Add a new Document Property of type String. Let's name it "collectionSelection".
      2. Set property value through "Fixed value".
      3. Click Add button and add the columns collections names you would like to add.
      4. Now click Script... button and select "Execute the script selected below:" and click New. 
      5. Add script parameter of type Visualization and select your data table. Let's name it "tablePlot".
      6. Paste-in the script below, edit it with relevant data, name it and click OK to close all settings.
      7. You can now select a collection of columns to display using Property Control.

    Script:

     # Copyright © 2017. TIBCO Software Inc.  Licensed under TIBCO BSD-style license.  
     from Spotfire.Dxp.Application.Visuals import TablePlot  
     
     # Get a handle to the data table 
     # tablePlot is the visualization parameter passed to the script to specify the table to work on. 
     dataTable= tablePlot.As[TablePlot]().Data.DataTableReference  
     
     # Get a handle to the table plot 
     table = tablePlot.As[TablePlot]()  
     
     # Get the ColumnCollection for the table plot 
     columns = table.TableColumns  
     
     if (Document.Properties["collectionSelection"] == "Financial" ):
     		columns.Clear() 
      # Add the relevant data table columns to the table plot ColumnCollection 	
     		columns.Add(dataTable.Columns.Item["Goods exports US$"]) 	
      	 	columns.Add(dataTable.Columns.Item["IncomeGroup"])  
    	
     if (Document.Properties["collectionSelection"] == "Population" ): 	
         	columns.Clear() 
     
     # Add the relevant data table columns to the table plot ColumnCollection 	
     		columns.Add(dataTable.Columns.Item["Population"]) 	
     		columns.Add(dataTable.Columns.Item["Urban Population %"]) 	
     		columns.Add(dataTable.Columns.Item["Life Expectancy at Birth (years)"])  
     if (Document.Properties["collectionSelection"] == "Other" ): 	
     		columns.Clear() 
        
     # Add the relevant data table columns to the table plot ColumnCollection 	
     		columns.Add(dataTable.Columns.Item["Internet Subscribers"]) 	
     		columns.Add(dataTable.Columns.Item["Power Consumption (kWh)"])
     

    You can download the attached CollectionSelection.dxp to see the property control in action.

    References

    License:  TIBCO BSD-Style License

    columns_selection_-_example.dxp

    columns_selection_-_script.txt

    columns_collection_selection_-_example.dxp

    columns_collection_selection_-_script.txt

    • Like 2

    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...