Jump to content
  • Update Y axis expressions of a line chart based on multi select list box using IronPython


    from Spotfire.Dxp.Data import *
    from Spotfire.Dxp.Application.Visuals import *
    from System.Collections.Generic import List
    from Spotfire.Dxp.Data import DataPropertyClass
    selection = Document.Data.Properties.GetProperty(DataPropertyClass.Document, "lbMetrics").Value
    #print str(selection)[1:-1]
    allMetrics = ['Presented' , 'Interested', 'Fulfilled', 'Total_Revenue', 'Take_Rate', 'VPM', 'AOV']
    
    Presented = '''
    	CASE  
    
    	WHEN DocumentProperty("sRollingDaysTrend")=7 THEN 
    	 Sum([Presented]) OVER (LastPeriods(7,[Create_Dt])) / DocumentProperty("sRollingDaysTrend")
    
    	WHEN DocumentProperty("sRollingDaysTrend")=14 THEN 
    	 Sum([Presented]) OVER (LastPeriods(14,[Create_Dt])) / DocumentProperty("sRollingDaysTrend")
    	 
    	WHEN DocumentProperty("sRollingDaysTrend")=30 THEN 
    	 Sum([Presented]) OVER (LastPeriods(30,[Create_Dt])) / DocumentProperty("sRollingDaysTrend")
    	 
    	END As [Pres #]
    '''
    
    
    Interested = '''
    	CASE  
    
    	WHEN DocumentProperty("sRollingDaysTrend")=7 THEN 
    	 Sum([Interested]) OVER (LastPeriods(7,[Create_Dt])) / DocumentProperty("sRollingDaysTrend")
    
    	WHEN DocumentProperty("sRollingDaysTrend")=14 THEN 
    	 Sum([Interested]) OVER (LastPeriods(14,[Create_Dt])) / DocumentProperty("sRollingDaysTrend")
    	 
    	WHEN DocumentProperty("sRollingDaysTrend")=30 THEN 
    	 Sum([Interested]) OVER (LastPeriods(30,[Create_Dt])) / DocumentProperty("sRollingDaysTrend")
    	 
    	END As [Interested]
    '''
    
    
    str = ''
     
    for s in selection:
    	for a in allMetrics:
    		if s==a:
    			if len(str) == 0:
    				str += eval(a)
    			else:
    				str += ',' + eval(a)
    		else:
    			pass
    
    #print str
    viz = viz.As[Visualization]()
    viz.YAxis.Expression = ""
    
    viz.YAxis.Expression = str
    viz.YAxis.IndividualScaling = True
    viz.YAxis.IndividualScalingMode = IndividualScalingMode.Color
    viz.YAxis.Scale.ShowGridlines = True
     

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...