This article explains how to Change Y Axis Expression with formatting and show/hide rules in a bar chart using Iron Python
Introduction
Based on drop down value, below code can update y-axis expression, format the axis and select the correct required show/hide rule from visualization properties.
Sample Code
# 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
Recommended Comments
There are no comments to display.