Jon
Jon

Reputation: 161

How to hide and show the legend in visualization - spotfire

I have a multiple bar chart both of them have a legend. I have a button in text area the will trigger to show or hide those legend in visualization. Does anyone have the idea using iron python. THank you in advance.

so far i have this code in my action control that works only in one bar chart.

#this script hide and show the legend
from Spotfire.Dxp.Application.Visuals import *

myVis = myVis.As[Visualization]()

#Hide the legend
if myVis.Legend.Visible :
    myVis.Legend.Visible = False

else :

    myVis.Legend.Visible = True

Upvotes: 1

Views: 1131

Answers (1)

Mark P.
Mark P.

Reputation: 1827

myVis = myVis.As[Visualization]() is only referencing one visualization on the page. Thats why only one legend is being disabled/enabled. You have two choices. One, Add another parameter like myVis2 and duplicate your code to enable/disable for that parameter. Two, write a loop that finds all bar charts on the page and enables/disables. That would look something like this:

#For the active page
for vis in Document.ActivePageReference.Visuals:
    #If the viz is of type BarChart
    if vis.TypeId == VisualTypeIdentifiers.BarChart:

After that, apply the code to enable/disable by vis.

*I did not run that code in Spotfire yet, but it should be very close to what you need

Upvotes: 1

Related Questions