如何将数据对象输出到文本中。
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:迭代非序列 类型
如何获取绘图数据,以便最终标记其中的项目?
答案 0 :(得分:4)
您的问题是您从可视化中获取数据表本身,该数据表本身不是您的记录集合,而是包含行值集合的列集合。
以下应该会让你到那里。我使用了一个数据集,其中列" test1"保存6行,值为1到6(含)。
以下代码的总体流程如下:
代码:
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"]