Jump to content

Ironpython to set document colour scheme


Ashni Sedani

Recommended Posts

Hi all,

 

Looking for some help with document colour schemes in a scatter plot. I have a property control with which the user can select a column to colour the scatter plot by. I want to implement an IronPython script which will run when this property changes, and based on the property value, apply a particular colour scheme.. e.g.

 

if property value = a then

set visualisation colour scheme as a

if property value = b then

set visualisation colour scheme as b

 

Any ideas

 

Many thanks.

Link to comment
Share on other sites

The following script demonstrates how to apply Color Schemes using an IronPython script:

 

from Spotfire.Dxp.Application.Visuals import *

 

#viz is an input parameter, referenced to the visualization where Color Scheme needs to be applied.

vis = viz.As[barChart]() #Replace BarChart with your visualization type identifier.

 

vis.ColorAxis.Coloring.Apply("ColorSchemeName") #ColorSchemeName should be stored in the document or library.Then you just need to wrap thevis.ColorAxis.Coloring.Apply() line with your conditional if else statement per standard IronPython syntax.

 

For example:

 

from Spotfire.Dxp.Application.Visuals import *

 

#viz is an input parameter, referenced to the visualization where Color Scheme needs to be applied.

vis = viz.As[barChart]() #Replace BarChart with your visualization type identifier.

 

if Document.Properties["myProp"] == "A":

vis.ColorAxis.Coloring.Apply("ColorSchemeA") #ColorSchemeA should be stored in the document or library.

elif Document.Properties["myProp"] == "B":

vis.ColorAxis.Coloring.Apply("ColorSchemeB") #ColorSchemeB should be stored in the document or library.

Link to comment
Share on other sites

  • 7 months later...

Hello,

I have tried the above steps to apply a custom color scheme based on document property control value, however, i get an error as below -

AttributeError: 'Visual' object has no attribute 'ColorAxis'

System.MissingMemberException: 'Visual' object has no attribute 'ColorAxis'

What can be causing this Can you please help

 

from Spotfire.Dxp.Application.Visuals import BarChart, ConditionalColoring

from Spotfire.Dxp.Application.Visuals.ConditionalColoring import Coloring

 

vc = vis.As[barChart]()

print 'Object title: ' + vis.Title

 

if Document.Properties["OverviewDateFormat"] == ',"Year.Quarter.Month",0)':

vc.ColorAxis.Coloring.Apply("Test 3")

print "0"

elif Document.Properties["OverviewDateFormat"] == ',"Year.Quarter.Month",1)':

vc.ColorAxis.Coloring.Apply("Test 2")

print "1"

elif Document.Properties["OverviewDateFormat"] == ',"Year.Quarter.Month",2)':

vc.ColorAxis.Coloring.Apply("Test 1")

print "2"

print "End"

Link to comment
Share on other sites

  • 1 year later...

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