Jump to content

Switch color by property using Iron python


Go to solution Solved by David Boot-Olazabal,

Recommended Posts

Posted

Hi Team,

I use cross table where there is a need to switch the values based on color by property (shown in screenshot).

I don't see any API property to control this, any suggestions would help.

image.png.bfd0b6380ce9cd13041d9fbf3811c371.png

Posted (edited)

Hi David,

Thanks for helping out.

What I am looking for is, how to switch between 'cell values' and 'Region' here in cross table using Iron python script.(attached image below)
image.thumb.png.827c91417e97b184e232cd09260ce238.png

Edited by Prashant S A
  • Solution
Posted

Hi Prashant, 

My colleague has created a working script for this.

Since you're on 12.0.3 and we work in Spotfire 14, I'll add the script and explain what we have done.

The solution comprises of 3 steps:
- Add a new text area;
- set up a document property called colorBy (see screenshot below). This is a drop down list property with Fixed values (you should replace the Region row with your own variable name and add others if needed);
- create a new script in which you add a parameter for the crosstab (in the script, this is the cross_table). This script should be added to the text area in the form of a button (in the screenshot below, this is the 'change' button.

image.thumb.png.681eb86d07978ad4d6a0d20e5407d5f7.png

 

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

cross_table = cross_table.As[CrossTablePlot]()
colour_property = Document.Properties['colorBy']
categoryKey=CategoryKey(colour_property)
cross_table.ColorCategory = categoryKey

Now, when you select one of the values from the drop down list and hit the change button, you will see that the coloring changes slightly, since the Color by has changed from (Cell values) to Region (in our example).

If needed, you can let the script run automatically upon changing the document property colorBy, by adding the script to the property via the Script button (see screenshot).

Hope this helps you.

Kind regards,

David

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...