I've been trying to create an IronPython script to toggle my BarChart Horizontal Lines names with no luck.
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.
According to the Spotfire API, DisplayName only offers a get method, while CustomDisplayName offers both get and set.
Does anyone know how to create this toggle?
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.
With that in mind, I've created another set of IFs, looking for the "new" DisplayName and replacing them with the old ones.
# 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 = ' '