2

如何将数据对象输出为文本。

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

回报:

Spotfire.Dxp.Application.Visuals.VisualizationData 对象位于 0x000000000000002C [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

4

1 回答 1

5

您的问题是您从可视化中获取数据表本身,这不是记录的集合,而是包含行值集合的列集合。

下面应该可以带您到达那里。我使用了一个数据集,其中“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 或任何名称。只需确保选择 Visualization 作为 Type 并选择您的可视化。

或者,您可以输入数据表本身并跳过我获取数据表源的代码或在代码中显式调用表,如下所示:

coll = Application.GetService[DataManager]().Tables   
crossSource = coll.Item["TABLE_NAME"]
于 2015-03-20T15:07:46.393 回答