In this example, we use a Property Control to add columns to a Table Plot Visualization. For this exercise, the Underlying data table must have 6 columns called 'col1,col2,..,col6'
Ingredients:
* Data Table Visualization
* Text Area
* Property Control
Preparation:
1) Add a Data Table Visualization and a Text Area. Edit the Text Area and add a List box (multiple select) control. Create a new property called 'groups' and add Fixed values for each item. The display name can be something like 'Group 1' and the value, a comma separated list of columns i.e. 'col2,col3,col4'.
2) Click on the Script button and add 1 tbs of the following script. If there is no script button, you would need to add a button to trigger the script:
#This script takes myDataTable Visualization as a script parameter
#It adds columns to a Data Table based on a property. The property has a comma separated list of columns for the data table to show.
#get underlying data table
#remove all columns
Ingredients:
* Data Table Visualization
* Text Area
* Property Control
Preparation:
1) Add a Data Table Visualization and a Text Area. Edit the Text Area and add a List box (multiple select) control. Create a new property called 'groups' and add Fixed values for each item. The display name can be something like 'Group 1' and the value, a comma separated list of columns i.e. 'col2,col3,col4'.
2) Click on the Script button and add 1 tbs of the following script. If there is no script button, you would need to add a button to trigger the script:
#This script takes myDataTable Visualization as a script parameter
#It adds columns to a Data Table based on a property. The property has a comma separated list of columns for the data table to show.
from Spotfire.Dxp.Application.Visuals import TablePlot, VisualContent
from Spotfire.Dxp.Data import DataPropertyClass
#get underlying data table
dt=myDataTable.As[VisualContent]()
cols = dt.Data.DataTableReference.Columns
#remove all columns
dt.TableColumns.Clear()
#get document property
#get document property
selection = Document.Data.Properties.GetProperty(DataPropertyClass.Document, "groups").Value
#parse columns from selection
#parse columns from selection
for property in selection:
for col in property.split(","):
#add columns from document property (ignore duplicates)
try:
dt.TableColumns.Add(cols[str(col)])
except:
print col + " is already in table"
- Add a Visualization Script parameter called 'myDataTable'
ConversionConversion EmoticonEmoticon