How to sort a Bar Chart visualization using IronPython in TIBCO Spotfire®

Last updated:
10:27am Jun 29, 2020
 
Back to main IronPython scripting page

Introduction

For a Bar Chart visualization, bars can only be sorted if the X-axis is categorical. Note that the scale axis needs to be reversed when sorting the bars if their orientation is horizontal. This means that sorting the bar chart (Properties > Appearance > Sort bars by value) when the bars orientation is horizontal, will require reversing the category scale axis. However, if sorting the bar chart (Properties > Appearance > Sort bars by value) when the bars orientation is vertical, no scale axis needs to be reversed.

The following is a sample script showing how to sort bars while toggling between the different bar chart orientation:

Code sample

# Copyright © 2017. TIBCO Software Inc.  Licensed under TIBCO BSD-style license.

from Spotfire.Dxp.Application.Visuals import *

for  vis in Document.ActivePageReference.Visuals:
   if  vis.Title == "Bar Chart":
      vc = vis.As[BarChart]()      
      if (vc.Orientation == BarChartOrientation.Vertical):
         vc.Orientation = BarChartOrientation.Horizontal
         vc.SortedBars = 1
         vc.XAxis.Reversed = True
      else:
         vc.Orientation = BarChartOrientation.Vertical
         vc.SortedBars = 1
         vc.XAxis.Reversed = False

 

References

 

License:  TIBCO BSD-Style License