As a transitional step, this site will temporarily be made Read-Only from July 8th until the new community launch. During this time, you can still search and read articles and discussions.

While the community is read-only, if you have questions or issues requiring TIBCO review/response, please access the new TIBCO Community and select "Ask A Question."

You will need to register or log in or register to engage in the new community.

Change Y Axis Expression with formatting and show/hide rules in a bar chart using Iron Python

By:
Last updated:
7:48am Mar 27, 2020
Table of Contents
Sample Code
Based on drop down value, below code can update yaxis expression, format the axis and select the correct required show/hide rule from visualization prperties.
     
# varViz and varViz2 are input visulizations
# create required show/hide rules
# document property (yaxis) is a drop down which wil trigger the script

from Spotfire.Dxp.Application.Visuals import *
from Spotfire.Dxp.Application.Visuals import LabelVisibility
from Spotfire.Dxp.Data.Formatters import *
from Spotfire.Dxp.Data import *
visuals = Document.ActivePageReference.Visuals
formatter = DataType.Real.CreateLocalizedFormatter()
for vis in visuals:
 if vis == varViz:
  chart = vis.As[BarChart]()
for vis2 in visuals:
 if vis2 == varViz2:
  chart2 = vis2.As[BarChart]()
Rules = chart2.TryGetFilterRules()
myFilterRuleCollection = Rules[1]
varp = Document.Properties['yaxis']
if  varp == "value1":
 chart.YAxis.Expression = "Sum([col1]) as [Total]"
 formatter.Category = NumberFormatCategory.Number
 formatter.DecimalDigits = 0
 chart.YAxis.Scale.Formatting.RealFormatter = formatter
 chart2.YAxis.Expression = "Sum([col1]) as [Total]"
 formatter.Category = NumberFormatCategory.Number
 formatter.DecimalDigits = 0
 chart2.YAxis.Scale.Formatting.RealFormatter = formatter
# short number and currency format
#formatter.Category = NumberFormatCategory.Currency
#formatter.ShortFormattingEnabled = True
 if myFilterRuleCollection.Count > 0:
    for myFilterRule in myFilterRuleCollection:
     if myFilterRule.DisplayName == "filterrule1":
      myFilterRule.Enabled = True
     if myFilterRule.DisplayName == "filterrule2":
      myFilterRule.Enabled = False
           
if varp == "value2":
 chart.YAxis.Expression = "your expression  as [col alias]"
 formatter.Category = NumberFormatCategory.Percentage
 formatter.DecimalDigits = 2
 chart.YAxis.Scale.Formatting.RealFormatter = formatter
 chart2.YAxis.Expression = "your expression  as [col alias]"
 formatter.Category = NumberFormatCategory.Percentage
 formatter.DecimalDigits = 2
 chart2.YAxis.Scale.Formatting.RealFormatter = formatter
 if myFilterRuleCollection.Count > 0:
    for myFilterRule in myFilterRuleCollection:
     if myFilterRule.DisplayName == "filterrule2":
      myFilterRule.Enabled = True
     if myFilterRule.DisplayName == "filterrule1":
      myFilterRule.Enabled = False