Jump to content

programatically change the color of the horizontal line in scatter plot with ironpython script


Nivedan Nasina

Recommended Posts

Please helpwith ironpython script:

I would like to 1) programatically change the color and line thickness of the horizontal line i added to my scatter plot vai the following script:

or

2) copy the color from another scatter plot horizontal line to a new scatter plot visualization that i have already created.

or

3) change the default color(from black) and line thickness of 2 - so that it sets to the proper color for new horizontal line adds

#################################################################

from Spotfire.Dxp.Application.Visuals import *

from Spotfire.Dxp.Application.Visuals.FittingModels import *

from Spotfire.Dxp.Application.Extension import *

#Get a reference to the current visualization

sp1 = Viz.As[scatterPlot]()

#Get a reference to all of the fitting models on the current visualization

fm1 = sp1.FittingModels

#Clear all custom lines so the button can be clicked multiple times without piling things on top of each other

fm1.Clear()

horizontalLine1 = sp1.FittingModels.AddHorizontalLine('45')

#################################################################

reference link

https://docs.tibco.com/pub/doc_remote/spotfire/7.6.0/doc/api/topic=html...

 

 

Thanks a lot for your help.

Link to comment
Share on other sites

Try something like this:

 

from System.Drawing import *

horizontalLine1=sp1.FittingModels.AddHorizontalLine('45')

myline=horizontalLine1.Line

myline.LineStyle=LineStyle.Dot

myline.Width=2

myline.Color=Color.Black.#see System.Drawing namespace

myline.IsBackground=False. #set to Foreground in this case

myline.CustomDisplayName='my line name'

 

so horizontalLine1 is one ofReferenceLineFittingModels

myline=vcline.Line is aReferenceCurve, which has the properties being set here

Look at LineStyle Enumeration for different options of style.

Link to comment
Share on other sites

Ms Paolini,Thanks a lot for your help. I am trying to find this System.Drawing namespace in the documentation. Are there any easy ways to search or any pointers to find it would be of great help.I got it to work and below code should work for anyone who will look at this later on.there are a couple of "periods" which need to be removed(must have been a test for me ;)) ###############################################from Spotfire.Dxp.Application.Visuals import *from Spotfire.Dxp.Application.Visuals.FittingModels import *from Spotfire.Dxp.Application.Extension import *

from System.Drawing import *#Get a reference to the current visualizationsp1 = Viz.As[scatterPlot]()#Get a reference to all of the fitting models on the current visualizationfm1 = sp1.FittingModels#Clear all custom lines so the button can be clicked multiple times without piling things on top of each otherfm1.Clear()

horizontalLine1=sp1.FittingModels.AddHorizontalLine('45')myline=horizontalLine1.Linemyline.LineStyle=LineStyle.Singlemyline.Width=1myline.Color=Color.Green #see System.Drawing namespacemyline.IsBackground=False #set to Foreground in this casemyline.CustomDisplayName='my line name'###############################################

Link to comment
Share on other sites

Notes:

when i used the spotfire documentation for ironpython functions/api etc for version 7.6 there was no search feature available....

https://docs.tibco.com/pub/doc_remote/spotfire/7.6.0/doc/api/topic=html...

but then i randomly stumbled upon the documentation for spotfire rev 11 and saw that there was search feature:

https://docs.tibco.com/pub/doc_remote/sfire-analyst/11.0.0/doc/api/TIB_s...

I strongly recommend everyone to switch over to the latest documentation to avail the use of the search feature --- incase u didnt know.....

Link to comment
Share on other sites

  • 2 years later...

It works for my tests, The complete script, including the imports, is below. Note that LineStyle is part of the .NET API.

from System.Drawing import *from Spotfire.Dxp.Application.Visuals import *from Spotfire.Dxp.Application.Visuals.FittingModels import *from Spotfire.Dxp.Application.Extension import *#Get a reference to the current visualizationsp1 = Viz.As[scatterPlot]() horizontalLine1=sp1.FittingModels.AddHorizontalLine('45')myline=horizontalLine1.Linemyline.LineStyle=LineStyle.Dotmyline.Width=2myline.Color=Color.Black #see System.Drawing namespacemyline.IsBackground=False #set to Foreground in this casemyline.CustomDisplayName='my line name'
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...