Jump to content
  • How to progressively filter the data for each value in the column in Spotfire® using IronPython Scripting


    This article explains how to progressively filter the data for each value in a column, one at a time using IronPython.

    Introduction

    This article describes how you can progressively filter the data one by one for each value in the column. For example, if you have the data from the year 1999 to 2010, then you can filter the data for each year one by one starting from 1999. Refer to the attached analysis file for your reference.

    Code Sample

    # Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license.
    
    import Spotfire.Dxp.Application.Filters as filters
    import Spotfire.Dxp.Application.Filters.ItemFilter
    from Spotfire.Dxp.Application.Filters import FilterTypeIdentifiers
    from Spotfire.Dxp.Data import DataProperty, DataType, DataPropertyAttributes, DataPropertyClass
    
    myPanel = Document.ActivePageReference.FilterPanel #Gets the filter panel from the page where script is getting executed
    myFilter= myPanel.TableGroups[0].GetFilter("Year") #Gets the requred filter from the filter panel
    
    myFilter.FilterReference.TypeId = FilterTypeIdentifiers.ItemFilter #Converts the filter type to Item Filter
    itemFilter = myFilter.FilterReference.As[filters.ItemFilter]() 
    
    whichCol = itemFilter.DataColumnReference #Gets the DataColumn instance associated with this filter.
    
    #Create a column property of integer data type that will keep on iterating over that Item Filter
    if (whichCol.Properties.PropertyExists("CurrentStep") == False):
        myProp = DataProperty.CreateCustomPrototype("CurrentStep",0,DataType.Integer,DataPropertyAttributes.IsVisible|DataPropertyAttributes.IsEditable) #Here CurrentStep is a column property 
        Document.Data.Properties.AddProperty(DataPropertyClass.Column, myProp)
        whichCol.Properties.SetProperty("CurrentStep",0)
        Document.Properties["setCurrentYear"] = "All Years"  #Sets the value of the label to All years. Data is displayed for all the years.
    else:
        whichVal = whichCol.Properties.GetProperty("CurrentStep") # Gets the value stored in that column property
        
        if (whichVal == itemFilter.Values.Count): #Reset the value of the column property to 0 once it is reached to the total number of values present in that Item Filter 
        	whichCol.Properties.SetProperty("CurrentStep",0)
            Document.Properties["setCurrentYear"] = "All Years"
     
        else:
            itemFilter.Value = itemFilter.Values.Item[whichVal] #Item Filter gets its value by taking the value stored in the column property as its index
            whichCol.Properties.SetProperty("CurrentStep",whichVal+1) #increments the value stored in the column property for next iteration
            Document.Properties["setCurrentYear"] = "Year : " + str(itemFilter.Value)
     

    References

     

    License:  TIBCO BSD-Style License

    Back to IronPython Scripting in Spotfire Examples:  https://community.spotfire.com/s/article/IronPython-Scripting-in-Spotfire

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...