根据Spotfire上标记的行更改列标题

问题描述 投票:0回答:1

我在一个页面上有两个交叉表。

第一个交叉表是一个摘要,其横轴表示“组件”,纵轴表示“设施”。单元格值显示颜色“RED”,“YELLOW”或“NA”。第二个交叉表是汇总表上标记行的向下钻取,水平轴“组件”和“类型”在垂直轴上。单元格值是计数函数。

我需要的是在钻取中将每个组件下面标记的颜色显示出来。

Summary
+----------+--------+-------+--------+
| Facility | COMP1  | COMP2 | COMP3  |
+----------+--------+-------+--------+
| FAC1     | NA     | RED   | RED    |
| FAC2     | YELLOW | NA    | RED    |
| FAC3     | RED    | RED   | YELLOW |
+----------+--------+-------+--------+


Drilldown (If I mark the FAC2 row)
+-------+--------+-------+
| Type  | COMP1  | COMP3 |
+       + YELLOW +  RED  +
|-------|--------|-------|
| TYPE1 | 12     |       |
| TYPE2 | 11     | 4     |
+-------+--------+-------+

有没有人知道交叉表是否可行?关于如何做的任何提示?我很感激帮助。

谢谢,约翰

编辑:我这样做是为了无法对交叉表的列标题进行着色,所以如果有人有替代方案,我会很感激。

目前使用Spotfire 7.11

r spotfire tibco
1个回答
1
投票

好的。我在这里忍受,因为我已经破解了一个解决方案。我会说,我对你的数据结构做了一些假设。根据数据结构的不同,答案可能需要稍加修改。

这是我的数据结构:

enter image description here

第1步:创建两个文档属性以保存标题的值。我创建了两个名为“tableTitle1”和“tableTitle2”的文档属性(详细信息交叉表中的每一列都有一个)。创建一个文档属性以保存r脚本将传递给我们的DateTime值(稍后将讨论)。我把我的名字命名为“时间”。

第2步:创建交叉表。确保第一个交叉表使用“标记”标记,第二个交叉表由“标记”标记限制。在第二个交叉表中,确保标题看起来像这样:Count([Comp1]) as [Comp1 ${tableTitle1}], Count([Comp3]) as [Comp2 ${tableTitle2}]。您需要使用在步骤1中创建的文档属性。

第3步:创建python脚本。代码如下:

from System.Collections.Generic import List
from Spotfire.Dxp.Data import *

# Create a cursor for the table column to get the values from.
# Add a reference to the data table in the script.
dataTable = Document.Data.Tables["SOTest"]
cursor = DataValueCursor.CreateFormatted(dataTable.Columns["Comp1"])

# Retrieve the marking selection
markings = Document.Data.Markings["Marking"].GetSelection(dataTable).AsIndexSet()

# Create a List object to store the retrieved data marking selection
markedata = List [str]();

# Iterate through the data table rows to retrieve the marked rows
for row in dataTable.GetRows(markings, cursor):
    value = cursor.CurrentValue
    if value <> str.Empty:
        markedata.Add(value)

# Get only unique values
valData = List [str](set(markedata))

# Store in a document property
Document.Properties["tableTitle1"] = ', '.join(valData)

####DO IT AGAIN FOR THE SECOND COLUMN#####

# Create a cursor for the table column to get the values from.
# Add a reference to the data table in the script.
cursor = DataValueCursor.CreateFormatted(dataTable.Columns["Comp2"])

# Create a List object to store the retrieved data marking selection
markedata = List [str]();

# Iterate through the data table rows to retrieve the marked rows
for row in dataTable.GetRows(markings, cursor):
    value = cursor.CurrentValue
    if value <> str.Empty:
        markedata.Add(value)

# Get only unique values
valData = List [str](set(markedata))

# Store in a document property
Document.Properties["tableTitle2"] = ', '.join(valData)

第4步:创建一个R脚本,以便在标记数据时启动python脚本。这将是一个非常简单的R脚本。代码如下:

markedTable <- inputTable
time <- Sys.time()

应取消选中允许缓存的复选框。输出参数时间应该转到文档属性时间。输入参数inputTable应该是您的数据表,所有列,并且应该受标记限制。确保选中自动刷新功能复选框。

第5步:将python脚本映射到时间文档属性。在“编辑”>“文档属性”对话框的“属性”下,将我们创建的python脚本分配给文档属性。每次表上的标记发生变化时,R脚本都会更改当前的日期时间,从而为我们运行python脚本。

第6步:观察魔术的发生。

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.