简体   繁体   English

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

[英]How To Toggle Lines & Curves Names Visibility On Spotfire With Iron Python?

I've been trying to create an IronPython script to toggle my BarChart Horizontal Lines names with no luck. 我一直在尝试创建一个IronPython脚本来切换我的BarChart水平线名称,但是没有运气。

I would like to achieve this with a button click: 我想通过单击按钮来实现: 在此处输入图片说明

The code I am currently using is: 我当前使用的代码是:

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 = ''

But, when I get to the "Show = true", the code does not change the CustomDisplayNames. 但是,当我进入“ Show = true”时,代码不会更改CustomDisplayNames。

According to the Spotfire API, DisplayName only offers a get method, while CustomDisplayName offers both get and set . 根据Spotfire API, DisplayName仅提供get方法,而CustomDisplayName提供getset

Does anyone know how to create this toggle? 有人知道如何创建此切换吗?

I wrote a blog post on how to do this. 我写了一篇有关如何执行此操作的博客文章。 Please go here -- https://datashoptalk.com/ironpython-in-spotfire-turning-lines-curves-on-and-off/ . 请转到此处-https://datashoptalk.com/ironpython-in-spotfire-turning-lines-curves-on-and-off/ The code will vary depending on what you have on the page. 代码将根据页面上的内容而有所不同。 Please upvote if you get to the right answer with this post. 如果您对此帖子的答案是正确的,请进行投票。

I've managed to get it working in a hideous way. 我设法使它以一种可怕的方式工作。 Will share it here if anyone needs it, but please, would love to find a proper way to do it. 如果有人需要,可以在这里分享,但是请您找到一种合适的方法。

Even though Spotfire API documentation mentions that the ReferenceCurve.DisplayName is a read-only Property (only have the get method), it looks like it's being changed when CustomDisplayName is updated. 即使Spotfire API文档提到ReferenceCurve.DisplayName是一个只读属性(仅具有get方法),但在更新CustomDisplayName时似乎已对其进行了更改。

With that in mind, I've created another set of IFs , looking for the "new" DisplayName and replacing them with the old ones. 考虑到这一点,我创建了另一组IF ,寻找“新” 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 = '   '

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM