如何使用 Iron Python 切换 Spotfire 上的直线和曲线名称可见性?

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

我一直在尝试创建一个 IronPython 脚本来切换我的条形图水平线名称,但没有成功。

我想通过单击按钮来实现此目的:

我当前使用的代码是:

from System.Drawing import Color
from Spotfire.Dxp.Application.Visuals import *

# vis parameter referencing an existing BarChart visualization
vis = vis.As[BarChart]()

# Read the document property with the toggle value (true/false)
Document.Properties['GenericToggleLineNames'] = not Document.Properties['GenericToggleLineNames']

#Loop through all the Lines & Curves collection
if Document.Properties['GenericToggleLineNames']:
    for fm in vis.FittingModels:
        if fm.Line.DisplayName == 'Defined Underload Limit':
            fm.Line.CustomDisplayName = 'Defined Underload Limit'
        elif fm.Line.DisplayName == 'Defined Warning Limit':
            fm.Line.CustomDisplayName = 'Defined Warning Limit'
        elif fm.Line.DisplayName == 'Defined Critical Limit':
            fm.Line.CustomDisplayName = 'Defined Critical Limit'
else:
    for fm in vis.FittingModels:
        if fm.Line.DisplayName == 'Defined Underload Limit':
            fm.Line.CustomDisplayName = ''
        elif fm.Line.DisplayName == 'Defined Warning Limit':
            fm.Line.CustomDisplayName = ''
        elif fm.Line.DisplayName == 'Defined Critical Limit':
            fm.Line.CustomDisplayName = ''

但是,当我到达“Show = true”时,代码不会更改 CustomDisplayNames。

根据 Spotfire API,DisplayName 仅提供 get 方法,而 CustomDisplayName 提供 getset

有人知道如何创建这个切换吗?

python bar-chart ironpython spotfire tibco
3个回答
0
投票

我写了一篇关于如何做到这一点的博客文章。请转到此处 - https://datashoptalk.com/ironpython-in-spotfire-turning-lines-curves-on-and-off/。该代码将根据页面上的内容而有所不同。如果您在这篇文章中得到正确答案,请点赞。


0
投票

我设法让它以一种可怕的方式工作。如果有人需要它,我会在这里分享它,但是请希望找到一种合适的方法来做到这一点。

尽管 Spotfire API 文档提到 ReferenceCurve.DisplayName 是一个只读属性(只有 get 方法),看起来它随着 CustomDisplayName 的更新而改变。

考虑到这一点,我创建了另一组 IFs,寻找“新”DisplayName 并将其替换为旧的。

# Imports
from System.Drawing import Color
from Spotfire.Dxp.Application.Visuals import *

#Add a vis parameter referencing an existing LineChart visualization
vis = vis.As[BarChart]()

#Loop through all the Lines & Curves collection
Document.Properties['GenericVisualisationDescriptions'] = not Document.Properties['GenericVisualisationDescriptions']

if Document.Properties['GenericVisualisationDescriptions']:
    for fm in vis.FittingModels:
        if fm.Line.DisplayName == ' ':
            fm.Line.CustomDisplayName = 'Defined Underload Limit'
        elif fm.Line.DisplayName == '  ':
            fm.Line.CustomDisplayName = 'Defined Warning Limit'
        elif fm.Line.DisplayName == '   ':
            fm.Line.CustomDisplayName = 'Defined Critical Limit'
else:
    for fm in vis.FittingModels:
        print fm.Line.DisplayName
        print fm.Line.CustomDisplayName
        if fm.Line.DisplayName == 'Defined Underload Limit':
            fm.Line.CustomDisplayName = ' '
        elif fm.Line.DisplayName == 'Defined Warning Limit':
            fm.Line.CustomDisplayName = '  '
        elif fm.Line.DisplayName == 'Defined Critical Limit':
            fm.Line.CustomDisplayName = '   '

0
投票

具体操作方法如下:

# Imports
from System.Drawing import Color
from Spotfire.Dxp.Application.Visuals import *

#Add a vis parameter referencing an existing LineChart visualization
vis = vis.As[BarChart]()

#Loop through all the Lines & Curves collection
Document.Properties['GenericVisualisationDescriptions'] = not Document.Properties['GenericVisualisationDescriptions']

for fm in vis.FittingModels:
    labels_tooltips=fm.Line.Details
    if Document.Properties['GenericVisualisationDescriptions']:
        for lt in labels_tooltips:
            lt.ShowInLabel=True    #turns label on
            lt.ShowInTooltip=True  #turns tooltip on
    else:
        for lt in labels_tooltips:
            lt.ShowInLabel=False   #turns label off
            lt.ShowInTooltip=False #turns tooltip off
© www.soinside.com 2019 - 2024. All rights reserved.