Jump to content

Display a Checkbox to reverse Y-Axis scale in a Text Box?


apreble
Go to solution Solved by Niko Maresco,

Recommended Posts

Good morning,

Does anyone know of a way that I can add a checkbox to a Text Area to make it an option for users to reverse the Y-Axis scale without having to open the Properties of the visual? 

Thanks!

Link to comment
Share on other sites

  • Solution

hi apreble,

you could do this with an Action Control or a Property Control, but unfortunately there is no checkbox or radio button control in Spotfire. as an alternative, either a Drop-down List Property Control or an Action Control attached to an IronPython script can sort this out for you. i'll outline the steps and provide a script for the latter. i'm assuming you're using a Bar Chart here :)

  1. in your Text Area, add a new Action Control: image.png.efdafbb1b76e437ceabf11736f4e0bd0.png
  2. enter a value for Display text and set the Control type to either Button or Link (i recommend Button with a Display text like "Reverse Y-Axis")
  3. choose Script from the action types on the left, then click Add >> New script...
  4. provide a name for the script, like "reverseYAxis" (no spaces here!)
  5. paste the below script into the Script field:
    # import the class reference for a Bar Chart
    from Spotfire.Dxp.Application.Visuals import BarChart
    # cast the `visual` Parameter as a BarChart class
    bar_chart = visual.As[BarChart]()
    # toggle the YAxis.Reversed property from False->True or True->False
    bar_chart.YAxis.Reversed = not bar_chart.YAxis.Reversed
  6. click the Add... button to add a new Parameter. name it "visual" and under Debug value choose your visualization from the dropdown, then click OK
  7. click Run Script to verify that it's working correctly, and then confirm all open dialogs

and there you have it :)

here's a screenshot of all the open dialogs in case it's useful to see the whole thing completed

image.thumb.png.5192d885bc53047faa548aee44c24f38.png

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

@Niko Maresco Thank you for the helpful step-by-step! I have 2 questions.... first one- this visual is actually a scatterplot, so I substituted all the "Bar Charts" w/"Scatter plot". Unfortunately this didn't work, but maybe I'm not naming the scatter plot function correctly. Second question- I noticed your version of IronPython was 3.4, and I only have options for 2.0 and 2.7. Is this causing any issues? image.thumb.png.6fa61521f1a12b84aea93c1beae00f38.png

Link to comment
Share on other sites

hi apreble,

aha, your hypothesis is correct :) in this case, you want "ScatterPlot". here's the complete script:

# import the class reference for a Scatter Plot
from Spotfire.Dxp.Application.Visuals import ScatterPlot
# cast the `visual` Parameter as a ScatterPlot class
scatter_plot = visual.As[ScatterPlot]()
# toggle the YAxis.Reversed property from False->True or True->False
scatter_plot.YAxis.Reversed = not scatter_plot.YAxis.Reversed

the version of Python doesn't affect anything in this case. the available selections are dependent on your installed version of Spotfire (i am using 14.4.0).

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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...