In Spotfire,we have direct option to loop thru Data Table but not for Cross Table.
Below is the python script to capture the Cross Table Data into 2D Array and then it can be used for Loop Thru as per your requirement.
import System
from System.IO import *
from Spotfire.Dxp.Data import *
from Spotfire.Dxp.Application. Visuals import *
from Spotfire.Dxp.Data.Import import *
from System import Byte
memStream = MemoryStream();
sWriter = StreamWriter(memStream);
#Exporting the data to Memory Stream
crossTable.As[CrossTablePlot]( ).ExportText(sWriter);
memStream.Seek(0, SeekOrigin.Begin);
sReader = StreamReader(memStream);
str="";
# 2D Array
lst=[[]];
i=0;
#Reading Memory Stream and then saving it to 2D Array
while(sReader.Peek() >=0):
a=sReader.ReadLine();
a=a.replace("\t", "!");
temparray=a.split("!");
j=0;
count=len(temparray);
#print count
while j < count:
lst[i].append(temparray[j]);
j=j+1;
i=i+1;
lst.append([])
del lst[len(lst)-1]
#Final Arrary
print lst
This block is so very helpful! Thank you for sharing your knowledge.
ReplyDeleteI would like to know, can we setup button for users to switch off/on Cross grand and subtotals in Web player? I know this can be done when Cross table name is fixed but not when ${Autotitle} is used. Any work around suggestion would be great! Thank you