Přejdi na obsah Přejdi na navigaci

ÚvodBlogHow to set a specific filter in Tibco Spotfire using IronPython script

How to set a specific filter in Tibco Spotfire using IronPython script

In my previous article, I showed how to create a drop-down filter without any coding. The principle lies in the addition of a condition to limiting the expression of each chart that should be filtered. The drop-down list is connected to document property and the same document property is then used in the condition(s). Change in drop-down list is reflected in an adjustment of document property, which adjusts limitation of data in each chart where we changed the data limiting expression. As you probably feel from my description, this approach has several disadvantages. All of them can be overcome with a different approach. As the title of the article indicates, the different solution is the usage of the IronPython script which would control the actual filter in the filtering panel. Ok, so what is the goal for today? The goal is to create a drop-down list that will behave as a filter. In fact, it will be document property connected to the IronPython script which will control the filter, but for the end-user, it will behave exactly like a typical Spotfire filter.

If you prefer video to the blog post, then visit our new Spotfire Youtube channel because I created also a video for this particular topic. I described my steps a little bit more in the video, therefore I recommend watching a video if you are a total beginner.

I will use the same sales data and the same simple bar chart as in my previous article. I have a column that consists of information about when each order happened. My goal is to create a drop-down filter that would be based on this column. You need to create a text area and add drop-down list property control.

drop-down list property control

Create new document property and assign it an appropriate data type. If you do not know which one, check the data type of the column that you want to use for filtering in the column properties section. In my case, it is an integer. Set property value through unique values in the column and select column, whose values should be used as options for filtering.

Drop-down list Year

Then click on the script button and select “execute the script selected below“ and click on New.

Execute the script selected below

Assign script some name and add following script:

from Spotfire.Dxp.Application.Filters import CheckBoxFilter

 

#refer to filter as checkbox

myYearFilter=Document.FilteringSchemes[0].Item[myDataTable]["YEAR_ID"].As[CheckBoxFilter]()

#print myYearFilter

for value in myYearFilter.Values:

myYearFilter.Uncheck(value)

myYearFilter.Check(Document.Properties['Year'])

 

You need to change the name of the document property and the name of the column. It is also needed to add script parameter for a data table.

Script parametrs

Select a data table that contains the column which will be used for filtering.

Data table

Confirm everything and check that your filter works!


Tomáš

Author: Filip Prochazka
filip.prochazka@dolphinconsulting.cz

Spotfire Version: 10.10

Created: 3/12/2021

Zpět na výpis rubriky