Business Intelligence Tools / Developers Corner

IronPython to Sort the Bars of a Combination Chart

  • Are you running an older version of Spotfire (7.9 or lower)?
  • Would you like to be able to sort the bars of a combination chart in the same way that you can sort the bars in a bar chart?
  • Would you like a little bit more control over the appearance of combination charts?
  • Are you working on IronPython skills?

The Problem

When my company was using Spotfire 7.9, a user asked for help sorting combination chart bars by the value on the y-axis.  Now, if this were a bar chart, it would be easy.  There is an option in the Properties — Appearance menu as shown below.

Sorting bars by value will generate an end result like this where the bars are ordered greatest to least, left to right.

If you are working in a more recent version of Spotfire, you’ll find the following menu in the combination chart Properties > Appearance.  Now, I am not precisely sure when this feature was added in.  It happened sometime between version 7.9 and 7.12.  This drop-down menu will update as you add columns of data to the y-axis.  Each column added will be a selectable option.  However, if you are in a version that doesn’t have this, you must use IronPython to sort.


The Solution — Screenshot of Code


The Solution — Code to Copy Paste

from Spotfire.Dxp.Application.Visuals import CategoryKey

from Spotfire.Dxp.Application.Visuals import CombinationChart

myCategoryKey1=CategoryKey(“Avg(Oil IP 5000)”)



Steps to Implement

  1. Add a Text Area
  2. Right-click, select Edit HTML
  3. Click the insert Action Control button
  4. Type in a name for the button, such as “Sort”
  5. Click the Script button
  6. Name the script.  Note, you may want to use this script more than once in a project.  I recommend using one script per page, which means give it a name to distinguish it from others in the project.
  7. Copy and paste the script.
  8. Create a parameter called “vis” and connect it to the combination chart.
  9. Change the visualization title name in the code.
  10. Click Run to test.

And you’re done!


Spotfire Version

Content created with Spotfire 7.12.


If You Like This, Check Out…

If you liked this post, check out one of these three other IronPython posts.



1 thought on “IronPython to Sort the Bars of a Combination Chart

  1. Pingback: IronPython to turn panels on and off

Leave a Reply

Your email address will not be published. Required fields are marked *