简体   繁体   中英

How to add/remove columns in CrossTable visualization in Spotfire using IronPython script plugged to button?

I have found info how to add/remove columns from table visualization. http://www.bearonspotfire.com/dynamic-tables-using-scripts-in-spotfire

from Spotfire.Dxp.Application.Visuals import VisualContent
## we need to import this as it is an enum and we want to refer to it
from Spotfire.Dxp.Application.Visuals import TablePlotColumnSortMode

## get the table visualisation
table = tableVisualisation.As[VisualContent]()

## check what option user selected and remove column (if present) of other column(s)
if selectedOrder == usagesName and table.TableColumns.Contains(dataTable.Columns[lastAccessedName]):
    table.TableColumns.Remove(dataTable.Columns[lastAccessedName])
elif selectedOrder == lastAccessedName and table.TableColumns.Contains(dataTable.Columns[usagesName]):
    table.TableColumns.Remove(dataTable.Columns[usagesName])

## add in new column assuming it isn't there already
if not table.TableColumns.Contains(dataTable.Columns[selectedOrder]):
    table.TableColumns.Add(dataTable.Columns[selectedOrder])

## set the sorting for the table
table.SortInfos.Clear();
table.SortInfos.Add(dataTable.Columns[selectedOrder], TablePlotColumnSortMode.Descending)

## changing the table resets the column size so lets fix it
addedColumn = table.TableColumns.TryGetTableColumn(dataTable.Columns[selectedOrder])[1]
addedColumn.Width = 120

I need to do the same for cross table visualization.

I have noticed that it is possible to modify the expression property of ColumnAxis which results in modificaton of the set of columns so it allows to add/remove the columns but it is not as tidy as in case of table visulization. – Jacek Sierajewski Sep 25 '14 at 20:52

crossTable.ColumnAxis.Expression = "" This fragment of code is modifying the content of Column Axis to contain only Clothing column. – Jacek Sierajewski Sep 26 '14 at 7:24

Another example of expression is <[Clothing] NEST [Groceries] NEST [Toys] NEST [Number of Items Purchased]>. I now can get the expressions created by tool simply by sending the property value to the Input text value. – Jacek Sierajewski Sep 26 '14 at 11:21

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM