簡體   English   中英

Spotfire IronPython腳本:獲取交叉表數據

[英]Spotfire IronPython script: get Cross Table data

如何將數據對象輸出為文本。

crossTable = markMe.As[CrossTablePlot]()
print crossTable.Data

返回:

位於0x000000000000002C的Spotfire.Dxp.Application.Visuals.VisualizationData對象[Spotfire.Dxp.Application.Visuals.VisualizationData]

我也嘗試過:

for text in crossTable.Data:
    print text

返回錯誤:

Microsoft.Scripting.ArgumentTypeException:對類型的非序列進行迭代

如何獲得繪圖數據,以便最終標記其中的項目?

https://docs.tibco.com/pub/doc_remote/spotfire/6.5.0/api/?topic=html/P_Spotfire_Dxp_Application_Visuals_Visualization_Data.htm

您的問題是您要從可視化中獲取數據表本身,這不是記錄的集合,而是包含行值集合的列的集合。

以下內容將帶您到達那里。 我使用了一個數據集,其中“ test1”列包含6行,其值包括1到6。

以下代碼的總體流程如下:

  1. 從Visual獲取數據表
  2. 設置變量
  3. 遍歷感興趣的列以獲得行值
  4. 使用一些比較來確定是否應標記該項目。
  5. 標記所有通過我們測試的項目。

碼:

from Spotfire.Dxp.Application.Visuals import CrossTablePlot
from Spotfire.Dxp.Data import IndexSet
from Spotfire.Dxp.Data import RowSelection
from Spotfire.Dxp.Data import DataValueCursor
from Spotfire.Dxp.Data import DataSelection

##Get our Data Table from our graph. Data Tables hold marking relations. 
##Visuals just point to a marking set you specify 
##and interact with it in the UI based on their DataTable.
crossTable = markMe.As[CrossTablePlot]()
crossSource = crossTable.Data.DataTableReference

##Get a Row Count
rowCount = crossSource.RowCount

##Index Set of all our rows
allRows = IndexSet(rowCount,True)

##Empty Index Set to fill with our desired markings
rowsToMark = IndexSet(rowCount,False)

##Pick the column we're interested in examining for values.
##You can create multiple cursors to look at multiple columns.
##Specify the name of your column. Mine is called test1.
colCurs = DataValueCursor.CreateFormatted(crossSource.Columns["test1"])

##Optional: Loop through to determine average value
colTotal = 0
for row in crossSource.GetRows(allRows, colCurs):
    colTotal += int(colCurs.CurrentValue)
colAvg = colTotal/rowCount

##loop through our rows and add what we want to our index.
for row in crossSource.GetRows(allRows, colCurs):
    ##Get the index of our current row in the loop
    rowIndex = row.Index

    ##Compare values and if TRUE then we add this row to our index
    ##Instead of hard coding you can refer to a document property
    ##or any other source of data like the average of your column.
    ##Optional: Print our current value to debug
    #if int(colCurs.CurrentValue) > (2.5):
    if int(colCurs.CurrentValue) > colAvg:
        print colCurs.CurrentValue + " was added to the index! =]"
        rowsToMark.AddIndex(rowIndex)
    else:
        print colCurs.CurrentValue + " was not added to the index... =["

##Set our marking equal to our rowsToMark index
Document.ActiveMarkingSelectionReference.SetSelection(RowSelection(rowsToMark),crossSource)

資料來源:

我自己的Spotfire客戶端和API知識

http://www.bearonspotfire.com/mark-rows-and-unmark-rows-using-scripts-in-spotfire

bearonspotfire也是編寫腳本的好資源。 我接受了他所做的工作,並在您的應用程序上做了一些改動。 他使用下拉菜單標記項目。

編輯diablo8226的問題:

flux(OP)和我在相同的假設下運行,即markMe作為相關可視化的輸入參數包含在內。 您也可以通過單擊“腳本輸入”窗口下方的“添加...”按鈕來包括此內容。 您可以使用markMe或任何名稱。 只需確保選擇“可視化”作為“類型”,然后選擇您的可視化。

或者,您可以輸入數據表本身,並跳過獲取數據表源的我的代碼,或使用如下代碼明確調用該表:

coll = Application.GetService[DataManager]().Tables   
crossSource = coll.Item["TABLE_NAME"]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM