- 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?
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
- Add a Text Area
- Right-click, select Edit HTML
- Click the insert Action Control button
- Type in a name for the button, such as “Sort”
- Click the Script button
- 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.
- Copy and paste the script.
- Create a parameter called “vis” and connect it to the combination chart.
- Change the visualization title name in the code.
- Click Run to test.
And you’re done!
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.
- Resetting Zoom Sliders with IronPython
- IronPython to Turn Labels On and Off
- IronPython to Toggle Map Layers On and Off
Guest Spotfire blogger residing in Whitefish, MT. Working for SM Energy’s Advanced Analytics and Emerging Technology team!