Jump to content
  • How to sort a Bar Chart visualization using IronPython in Spotfire®


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

    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

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...