How to enable each Y-axis (left and right, independently) to share the same dynamic scale

How to enable each Y-axis (left and right, independently) to share the same dynamic scale

book

Article ID: KB0076691

calendar_today

Updated On:

Products Versions
Spotfire Analyst All Versions

Description

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:
User-added image

There is no automatic way of aligning the multiple scales, but this article provides you with a custom sample of how to enable the two columns on the left side Y-axis to share the same scale, and that the scale range changes dynamically with filtering change on this page. Using this approach would result in the following configuration where both scales on the left y-axis are now matching:
User-added image

Issue/Introduction

This article explains how to enable each Y-axis (left and right, independently) to share the same dynamic scale

Resolution

High level steps
  1. Create a data function that gets the min and max column values and which runs when filter changes.
  2. Create an IronPython script that sets the axis range based on the min and max values from the data function above.
  3. Associate one of the output values of the data function to a dummy document property.
  4. Associate the IronPython script to this Document Property so it will be triggered when the document property changes.
Detailed steps
  1. Data (for versions 7.14 and lower, select Edit instead) >> Data Function Properties
    1. Click on "Register New"
    2. Name: Get Filtered Data
    3. Type: R Script - TIBCO Enterprise Runtime for R
    4. Description: Data function to get min and max column values and current time to z
    5. Script: 
       rankmin <- floor(min(rank)) rankmax <- floor(max(rank))+1 promotionmin <- floor(min(promotions)) promotionmax <- floor(max(promotions))+1 z <- Sys.time()
    6. Input Parameters >> Add >> rank, column, Allowed Data Types: All; promotions, column, Allowed Data Types: All 
    7. Output Parameters >> Add >> rankmin, rankmax, promotionmin, promotionmax and z
  2. Run
  3. Edit Parameters
    1. Check the "Refresh Function Automatically" checkbox
    2. Input (Input will come from the filter/marking. Make changes in the expressions as needed.)
      1. Select rank
        1. Input Handler: Expression
        2. Data Table: Your data table
        3. Expression:
           Avg([SalesAndMarketing].[Rank]) OVER ([SalesAndMarketing].[Region])
        4. Limit By: Filtering scheme
      2. Select promotions
        1. Input Handler: Expression
        2. Data Table: Your data table
        3. Expression:
           Sum([SalesAndMarketing].[Promotions]) OVER ([SalesAndMarketing].[Region])
        4. Limit By: Filtering scheme
    3. Output
      1. Select rankmin
        • Output Handler: Document Property >> New: rankmin
      2. Select rankmax
        • Output Handler: Document Property >> New: rankmax
      3. Select promotionmin
        • Output Handler: Document Property >> New: promotionmin
      4. Select promotionmax
        • Output Handler: Document Property >> New: promotionmax
      5. Select z
        • Output Handler: Document Property >> New: z
  4. OK >> Close (Save to Library if you wish to)
  5. File (for TS 7.x versions, select Edit instead) >> Document Properties >> Properties
    1. Select z
    2. Script >> Execute the script selected below
    3. New
    4. script name: set left axis range
    5. 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
    6. Script parameters: Add >> viz (your line chart).
  6. Click OK >> OK >> OK.

Additional Information

Doc:  ScaleAxis Properties