Jump to content

Set multiple columns on Y Axis of line chart using selections from several multi-select list boxes


Tiffany Lai

Recommended Posts

Hello,

I'm trying to create a line graph that is controlled by IronPython scripts. I am new to IronPython, so please excuse any misnomers. I have 8 multi-select list boxes where the user can choose the columns to be plotted on the Y Axis. The X-Axis will always be the same column, so we don't need to worry about that. I have the following script in a button that the user can click once they have selected the columns.

from Spotfire.Dxp.Application.Visuals import *

from Spotfire.Dxp.Data import DataPropertyClass

# Set up line graph

Vis = myLineGraph

vc = Vis.As[VisualContent]()

# Grab selected columns from the multi-select list box. This line of code worked on another visualisation where the columns on a table visualisation were populated by a multi-select list box. "Group 1" is the name of the property assigned to one of the multi-select list boxes.

selection_1 = Document.Data.Properties.GetProperty(DataPropertyClass.Document, "Group1").Value

#Set YAxis.

vc.YAxis.Expression = selection_1

This doesn't work as the vc.YAxis.Expression expectes a string and gets a list object instead. How can I configure the Y-Axis to plot the columns selected from the multi-select list boxes If it helps, I have illustrated what I am trying to accomplish in the screenshot.

Thank you,

T

Link to comment
Share on other sites

With selection_1 variable value, you cannot get it to work with Table visualization as well. You will need a loop to separate out values in stringlist and then add columns to table visualization

https://spotfired.blogspot.com/2014/04/add-columns-dynamically-to-data-t...

 

Regarding line chart, you can setup expression like $map("${Group1}", ",") in Line chart Y-Axis. So on selecting any number of values in Group1 listbox, it will automatically show values in line chart. You do not need Iron Python script for setting this up.

But if you have multiple listbox and want to show columns in same line chart, you can use iron python script to merge the selection from all listbox into one, which can then be passed to map function in Line Chart Y-Axis expression

from Spotfire.Dxp.Application.Visuals import *

 

from Spotfire.Dxp.Data import DataPropertyClass

vc = Vis.As[VisualContent]()

selection_1=Document.Properties["newprop1"] ## For listbox1

test=[] ##empty list

try:

for p in selection_1:

test.append(p)

except:

print 'no selection made'

 

try:

for p in Document.Properties["newprop2"]:

test.append(p)

except:

print 'no selection made'

 

Document.Properties["testprop"]=test ##Create a dummy testprop multilist box

 

print Document.Properties["testprop"]In Y-Axis, expression will be like $map("${testprop}", ",")

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