Date Posted:
Product: TIBCO Spotfire®
Product: TIBCO Spotfire®
Problem:
How to enable each Y-axis (left and right, independently) to share the same dynamic scale
Solution:
If you have a visualization that has both left and right Y-axis, and there are multiple columns on one or both sides of the Y-axes, you might want to have the scales on a single side sharing the same scale, which could be read easily by viewers of the visualization. Also, you may want to have the axis ranges changing along while the filters of the page changes. For example, this may be the default configuration where there are multiple columns on the left y-axis, and each has a different scale:
High level steps
- Create a data function that gets the min and max column values and which runs when filter changes.
- Create an IronPython script that sets the axis range based on the min and max values from the data function above.
- Associate one of the output values of the data function to a dummy document property.
- Associate the IronPython script to this Document Property so it will be triggered when the document property changes.
- Data (for versions 7.14 and lower, select Edit instead) >> Data Function Properties
- Click on "Register New"
- Name: Get Filtered Data
- Type: R Script - TIBCO Enterprise Runtime for R
- Description: Data function to get min and max column values and current time to z
- Script:
rankmin <- floor(min(rank)) rankmax <- floor(max(rank))+1 promotionmin <- floor(min(promotions)) promotionmax <- floor(max(promotions))+1 z <- Sys.time()
- Input Parameters >> Add >> rank, column, Allowed Data Types: All; promotions, column, Allowed Data Types: All
- Output Parameters >> Add >> rankmin, rankmax, promotionmin, promotionmax and z
- Run
- Edit Parameters
- Check the "Refresh Function Automatically" checkbox
- Input (Input will come from the filter/marking. Make changes in the expressions as needed.)
- Select rank
- Input Handler: Expression
- Data Table: Your data table
- Expression:
Avg([SalesAndMarketing].[Rank]) OVER ([SalesAndMarketing].[Region])
- Limit By: Filtering scheme
- Select promotions
- Input Handler: Expression
- Data Table: Your data table
- Expression:
Sum([SalesAndMarketing].[Promotions]) OVER ([SalesAndMarketing].[Region])
- Limit By: Filtering scheme
- Select rank
- Output
- Select rankmin
- Output Handler: Document Property >> New: rankmin
- Select rankmax
- Output Handler: Document Property >> New: rankmax
- Select promotionmin
- Output Handler: Document Property >> New: promotionmin
- Select promotionmax
- Output Handler: Document Property >> New: promotionmax
- Select z
- Output Handler: Document Property >> New: z
- Select rankmin
- OK >> Close (Save to Library if you wish to)
- File (for TS 7.x versions, select Edit instead) >> Document Properties >> Properties
- Select z
- Script >> Execute the script selected below
- New
- script name: set left axis range
- Script:
from Spotfire.Dxp.Application.Visuals import LineChart from Spotfire.Dxp.Application.Visuals import AxisRange vMin1 = Document.Properties["promotionmin"] vMin2 = Document.Properties["rankmin"] vMin = min(vMin1, vMin2) vMax1 = Document.Properties["promotionmax"] vMax2 = Document.Properties["rankmax"] vMax = max(vMax1, vMax2) newAxisRange = AxisRange(vMin, vMax) viz = viz.As[LineChart]() viz.YAxis.IndexedRange["Avg(Rank)"] = newAxisRange viz.YAxis.IndexedRange["Sum(Promotions)"] = newAxisRange
- Script parameters: Add >> viz (your line chart).
- Click OK >> OK >> OK.
Comments
0 comments
Article is closed for comments.