Jump to content

extracting values from datatable by index


achen1

Recommended Posts

53 minutes ago, achen1 said:

How do I extract the value from the first row of the "longname" column from my datatable called "calc_attributes_data" 

I am trying to dynamically change the title of my graph based on the value in the "longname" column of the first row

Link to comment
Share on other sites

Hi @achen1

Could this script work for you?
 

from Spotfire.Dxp.Data import *
from Spotfire.Dxp.Application.Visuals import *

#setup rows to select from rows to include
rowCount=table.RowCount
rowsToInclude = IndexSet(rowCount, True)
 
# Create a cursor to the Column we wish to get the values from
cursor = DataValueCursor.CreateFormatted(table.Columns["myCol"])
 
# Loop through all rows, retrieve value for specific column,
# Get the first value from the column
for row in table.GetRows(rowsToInclude, cursor):
	rowIndex = row.Index
	if rowIndex == 0:
		myTitleValue = cursor.CurrentValue
		break;


# Get myVis as a Visualization
myVis = VisualElement.As[Visualization]()

# Show (or hide) the title
myVis.ShowTitle = True

# Change the title
myVis.Title = 'My New Title has this value -> ' + myTitleValue

 

Link to comment
Share on other sites

7 hours ago, Vanessa Virginia Sucre Gonzalez said:

Hi @achen1

Could this script work for you?
 

from Spotfire.Dxp.Data import *
from Spotfire.Dxp.Application.Visuals import *

#setup rows to select from rows to include
rowCount=table.RowCount
rowsToInclude = IndexSet(rowCount, True)
 
# Create a cursor to the Column we wish to get the values from
cursor = DataValueCursor.CreateFormatted(table.Columns["myCol"])
 
# Loop through all rows, retrieve value for specific column,
# Get the first value from the column
for row in table.GetRows(rowsToInclude, cursor):
	rowIndex = row.Index
	if rowIndex == 0:
		myTitleValue = cursor.CurrentValue
		break;


# Get myVis as a Visualization
myVis = VisualElement.As[Visualization]()

# Show (or hide) the title
myVis.ShowTitle = True

# Change the title
myVis.Title = 'My New Title has this value -> ' + myTitleValue

 

how to I assign my crosstable to be my active table? The datatable is dynamic and will change based on the filters I apply so how can I set the "table" variable to be the data that is currently being displayed (after filters are applied)?

 

Link to comment
Share on other sites

Hi achen1,

There are two parameters that you have to set: table and Visual Element. The table would be your underlying data table and the Cross Table the Visual Element. See my example below, where I deactivated the ShowTitle line (line 23):
image.thumb.png.acfc0855ad81241991bfe4810edd74e5.png

Now, when you want to apply filters, so your representation of the data is changing in the Cross table, the underlying data table doesn't change actually. It's only the representation.

You can either opt for a 'removal' of rows from the data table by marking the values and select to delete the marked values (this adds a transformation on the data table, you can remove by applying another script or manually via the data canvas), or you can try to copy the filtered data to a new data table and build your Cross Table on that newly created data table.

Kind regards,

David

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...