Jump to content

Script to change Cross Table number format not working


Steve Fernandez

Recommended Posts

I'm kind of stumped here. I figured out how to use a script to change the formating on a bar/line chart. However, I'm not able to get similar examples of cross table formating to work. I'm using a document property to pass a parameter to show if the metric should be numberic (Orders) or currency (Sales). Cany anyone see why this won't work The doesn't generate an error, just won't update the format.

I'm hardsetting the axis column Orders to try to get this to work, but the column name is supposed to be dynamic of a document property.

 

from Spotfire.Dxp.Data import *

from Spotfire.Dxp.Application.Visuals import *

from Spotfire.Dxp.Data.Formatters import *

from Spotfire.Dxp.Data.Formatters import NumberFormatter, NumberFormatCategory

from Spotfire.Dxp.Data import DataType

 

 

# Create a new formatter object

NumberFormatter = DataType.Real.CreateLocalizedFormatter()

 

if Metric.find("Orders") > 0 :

NumberFormatter.Category = NumberFormatCategory.Number # Set number category to 'Number'

NumberFormatter.ShortFormattingEnabled = False

NumberFormatter.DecimalDigits = 0 # Set decimal places to 0

KPI = "Orders" #double check it's working

 

if Metric.find('Sales') > 0 :

NumberFormatter = DataType.Real.CreateLocalizedFormatter()

NumberFormatter.Category = NumberFormatCategory.Currency # Set number category to 'Currency'

NumberFormatter.ShortFormattingEnabled = True

NumberFormatter.DecimalDigits = 1 # Set decimal places to 1

KPI = "Sales" #double check it's working

 

NumberFormatter.GroupSeparatorEnabled = 1 # Enable group separator

 

# Apply the formatting

p = Document.ActivePageReference

 

#using a loop method to update all similar items and ignore text areas

for v in p.Visuals:

if (v.TypeId.Name) == "Spotfire.CrossTable" :

print(KPI);

#print(myVis.Formatting.IndexedRealFormatter["Orders"]);

myVis = v.As[CrossTablePlot]()

#myVis.YAxis.Scale.Formatting.Clear() # Clear the old formatting (probably unnecessary)

#myVis.YAxis.Scale.Formatting.CurrencyFormatter = NumberFormatter

myVis.Formatting.IndexedRealFormatter["Orders"] = NumberFormatter;

print (myVis.Title) #check that cross tabs were selected

else: print("skip") #check it correctly skipped text areas

Link to comment
Share on other sites

Well, I figured it out. The trick was since this is a cross table, Spotfire is using the column name value as the identifier, not the name itself. I realized this as I was trying to setup the sample file. So, here's the answer. Enjoy my bit of trickery.

I was experimenting the slide menu approach I found on another Spotfire tech site. Nifty, but I need to adjust its behavior to be more like an app.

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