Jump to content
  • How to Configure Coloring Schemes via Column Properties in Spotfire® using IronPython


    A common scenario is to have dedicated colors for known attributes and that those colors should be used in all visualizations. This can be achieved by creating a custom color scheme and assign that to the "DefaultCategoricalColorScheme" column property.

    Introduction

    A common scenario is to have dedicated colors for known attributes and that those colors should be used in all visualizations. This can be achieved by creating a custom color scheme and assign that to the "DefaultCategoricalColorScheme" column property. The code sample below shows how to do this using the Spotfire API from an IronPython script.

    Code Sample

    This example assume there is a column in the data set called "Region" and for the categories in that column, "EAST" should always be visualized as green and "WEST" as red. 

    # Copyright © 2019. TIBCO Software Inc. Licensed under TIBCO BSD-style license.
    
    from System.Drawing import Color
    
    # Remove previously added color scheme with the same name.
    for i in range(0, Document.ColoringTemplates.Count):
    	if Document.ColoringTemplates[i].DisplayName == "MyColoring":
    		Document.ColoringTemplates.RemoveAt(i)
    
    # add a new color scheme to the document	
    coloring = Document.ColoringTemplates.AddNew("MyColoring")
    map = coloring.AddCategoricalColorRule()
    map["WEST"] = Color.Red
    map["EAST"] = Color.Green
    
    # assign the color scheme to the DefaultCategoricalColorScheme column property
    Document.ActiveDataTableReference.Columns["Region"].Properties.SetProperty("DefaultCategoricalColorScheme", "MyColoring")
     

    Now, every visualization will use the custom color scheme for when color by "Region". Note: since the "NORTH" value was not included in the color scheme the blue color was picked by the Spotfire heuristics.

    converted-file.png.fce1fed02c9069d633d2e8f59773a1ea.png

    References

    License: TIBCO BSD-Style License

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...