- Would you like to turn labels on and off of a visualization without going into the properties menu?
- Would you like to learn more about IronPython?
A user contacted me today and asked how they could turn labels on and off without entering the properties dialog. They wanted to use a text area control to quickly turn labels on and off in a live demo. I knew IronPython could do the trick, although, I wasn’t quite sure about the code. A quick TIBCO Community search pulled up this link, and I was able to modify the code shown to meet my user’s needs.
In this post, I’ll show you how to attach IronPython to a property control that toggles labels on and off a scatter plot. Then, I’ll explain how to modify the code for other types of visualizations.
- Add a text area and toggle it into Edit mode.
- Click the button in the toolbar to add an input property control (data type: string) to the text area called “ToggleLables”. The case is important.
- While still in the Property Control dialog, click the Script button.
- Change the radio button to ‘Execute the script selected’.
- Click the New button.
- Name the script.
- Copy and paste the script below. It will look like this:
- Click the Add button to create a parameter called varViz and map it to your visualization.
- Next, click Run Script to make sure there are no errors.
- Click OK and exit out of the dialogs.
Copy and paste the script below, but use the screenshot above to mimick the indents.
from Spotfire.Dxp.Application.Visuals import *
from Spotfire.Dxp.Application.Visuals import LabelVisibility
visuals = Document.ActivePageReference.Visuals
for vis in visuals:
if vis == varViz:
scatterPlot = vis.As[ScatterPlot]()
if varProp == “N”:
scatterPlot.LabelVisibility = LabelVisibility.None
if varProp == “Y”:
scatterPlot.LabelVisibility = LabelVisibility.All
With the code provided, you should be able to enter “Y” or “N” into the input property control to turn the labels on and off.
Modification for Other Visualization Types
Now, this particular code example runs with a scatter plot. However, it’s easy to modify for any visualization type. Just lookup up the namespace here. Most are intuitive — ScatterPlot, BarChart, LineChart, etc. Now, you have a control that will allow you to more easily turn labels on and off.
Lastly, I am always looking to improve the content delivered to users and readers. Please provide feedback on my content, instructions, and explanations in the comments section. Thanks! (Julie)
Guest Spotfire blogger residing in Whitefish, MT. Working for SM Energy’s Advanced Analytics and Emerging Technology team!