Jump to content
  • IronPython script for Bar Chart Coloring


    Spotfire® allows the use of document properties to change the colours of a bar chart with buttons/drop down lists etc.

    Introduction

    Spotfire® allows the use of document properties to change the colours of a bar chart with buttons/drop down lists etc.

    Bar Chart Colouring

    The below script first locates the visualization in a page then casts it as a Bar chart. The colour of a value on the category axis is then set based on colors specified below. For example, The colour of the Bar denoting Apple is set to Red and the on denoting Banana is set to Yellow using the below script.

     # Copyright © 2017. TIBCO Software Inc.  Licensed under TIBCO BSD-style license.
     # Author: Andrew Berridge, February 2016
     #
     # Example of how to map colours to categorical items in a bar chart
     
     from Spotfire.Dxp.Data import * 
     from System.Collections.Generic import List
     from Spotfire.Dxp.Application.Visuals import *
     import System.Drawing.Color
     
     # Get a reference to a visual on the page specified
     def getVisual2(page, visualTitle):
         for vis in page.Visuals:
             if vis.Title == visualTitle:
                 return vis
         return None
     
     # Get the bar chart
     barchart = getVisual2(Document.ActivePageReference, "My Bar Chart").As[barChart]()
     
     # Clear the color axis coloring
     barchart.ColorAxis.Coloring.Clear()
     barchart.ColorAxis.Categorical.ColorMap["Apple"] = System.Drawing.Color.FromName("Red");
     barchart.ColorAxis.Categorical.ColorMap["Banana"] = System.Drawing.Color.FromName("Yellow");
     

    License:  TIBCO BSD-Style License

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...