achen1 Posted July 3 Share Posted July 3 Hello Spotfire team, I have a cross table visualization on Spotfire and I am trying to create an iron python script for a drop-down list property control that will apply a color filter on a column named "Norwood" in my visualization based on the logic if value in cell = "Runs" then color the cell red if value in cell = "OOC" then color the cell orange Ive been reading the spotfire API documentation for CrossTablePlot Class linked below but it is unclear to me how the Properties work https://docs.tibco.com/pub/doc_remote/sfire_dev/area/doc/api/TIB_sfire-analyst_api/Index.aspx Link to comment Share on other sites More sharing options...
Atheer Al Attar Posted July 3 Share Posted July 3 What will be the drop-down role here? Link to comment Share on other sites More sharing options...
achen1 Posted July 3 Author Share Posted July 3 The drop down will have two string options, "1" or "0". This is allow users to turn on or off the coloring logic that will be applied to the column named "Norwood" If user selects "1" then the color filtering will be applied If user selects "0" then the color filtering will be unapplied. I have started the Iron Python script (screenshot attached). Link to comment Share on other sites More sharing options...
David Boot-Olazabal Posted July 4 Share Posted July 4 Hi, Could you share an example dxp file? Kind regards, David Link to comment Share on other sites More sharing options...
Solution Anthony Alvarez Posted July 5 Solution Share Posted July 5 I would build two document color schemes (FilterOn and FilterOff). Your script can toggle between them. Create the two document color schemes: In the Cross Table properties > Colors page Create a "FitlerOn" color scheme group Save these settings using the Color Schemes button > Save As > Document Color Scheme... Call this one FilterOn Repeat the above steps for the FilterOff settings Notice that both of the Document Color Schemes exist and can be selected I tried to modify your code to include the toggle between the two Document Color Schemes: from Spotfire.Dxp.Application.Visuals import CrossTablePlot page = Document.ActivePageReference for vis in page.Visuals: if str(vis.Title) == "Combined Alert Table": myCrossTable = vis.As[CrossTablePlot]() if Document.Properties["ColorSwitch"] == "1": for coloring in myCrossTable.Colorings: if coloring.DisplayName == 'FilterOff' or coloring.DisplayName == 'FilterOn': print("filer ON") coloring.Clear coloring.Apply("FilterOn") else: #ColorSwitch is not 1 for coloring in myCrossTable.Colorings: if coloring.DisplayName == "FilterOff" or coloring.DisplayName == "FilterOn": print("filter OFF") coloring.Clear coloring.Apply("FilterOff") There may be many different color scheme groupings in your chart (some dates, some numbers, etc.). I tried to use the coloring.DisplayName to identify the correct color scheme grouping to toggle. Link to comment Share on other sites More sharing options...
Anthony Alvarez Posted July 5 Share Posted July 5 I was thinking of a different way to accomplish this. You can use a custom expression to toggle the color/logic on and off. Create a color scheme grouping I called my example "MyColumn" I included the column that contains the data like Runs, OOC, etc. Make sure you click on the "MyColumn" item in the color scheme groupings list and then enable the check box "color the grouping using anther expression" Edit the custom expression "Color Logic" and place the expression in First( Case DocumentProperty("ColorSwitch") when "1" then //Turn On case [Value] when "Runs" then "Red" when "OOC" then "Orange" else "Other" end when "0" then "Other" //Turn off else "Other" end ) Set the color mode to Unique values and configure the Red, Orange, Other, and Empty colors accordingly Link to comment Share on other sites More sharing options...
Anthony Alvarez Posted July 5 Share Posted July 5 The first and second solutions' legend would look like this Solution A uses an ironpython script and B uses the custom expression color logic. If you need solution B's legend to show the word "Runs" instead of "Red", you can build a color rule to correct the wording shown in the legend. Link to comment Share on other sites More sharing options...
achen1 Posted July 8 Author Share Posted July 8 Thanks Anthony this was super helpful. I went with Solution A Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now