Jump to content
  • IronPython script to Change Visual Data Table


    Spotfire® allows users to replace the data table in a visualization. This can be useful if the configuration of the vizualization doesn't need to change. If you change the data table using the Spotfire UI, the settings for the visualization are lost.

    Introduction

    TIBCO Spotfire® allows users to replace the data table in a visualization. This can be useful if the configuration of the visualization doesn't need to change. If you change the data table using the Spotfire UI, the settings for the visualization are lost.

    Change Visual Data Table

    The below script imports the necessary packages, finds the visualization called 'Weekly Delivery Risk Status', and replaces the underlying data table with 'my new data table'.

    # Copyright © 2017. TIBCO Software Inc.  Licensed under TIBCO BSD-style license.
    
    import System
    import Spotfire.Dxp.Application
    import Spotfire.Dxp.Data
    from Spotfire.Dxp.Data import *
    import Spotfire.Dxp.Data.AddColumnsSettings
    import Spotfire.Dxp.Data.DataTableCollection
    from Spotfire.Dxp.Data.Transformations import *
    from Spotfire.Dxp.Application.Visuals import VisualContent
    from Spotfire.Dxp.Data.Import import *
    from System.IO import Directory, Path
    from System.Collections.Generic import *
    from System.Collections.Generic import Dictionary
    from System.Collections import ArrayList
    import re
    
    
    
    def getDataTable(tableName):
    	try:
    		return Document.Data.Tables[tableName]
    	except:
    		raise ("Error - cannot find data table: " + tableName)
    
    def getVisual(visualTitle):
    
    	for vis in Document.ActivePageReference.Visuals: 
    		if vis.Title == visualTitle:		
    			return vis.As[VisualContent]()
    	
    	raise ("Error - cannot find visual: " + visualTitle)
    
    		
    
    vis = getVisual("Weekly Delivery Risk Status")
    		
    print vis.Data.DataTableReference.Name
    
    
    for dt in Document.Data.Tables:
    	print dt.Name
    	
    
    vis.Data.DataTableReference = getDataTable("my new datatable")
     

    License:  TIBCO BSD-Style License

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...