Jump to content
  • How to set colors from a Categorical Axis on a visualization and save ColorScheme to library in Spotfire® using IronPython Scripting


    Code sample script to set colors and save the color scheme to library

    Introduction

    Below is a sample script on how to set colors and save the color scheme to library

    Code Sample

    # Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license.
    
    
    from Spotfire.Dxp.Application.Visuals import *
    from Spotfire.Dxp.Application.Visuals import CategoryKey
    from System.Drawing import Color
    from System.Collections.Generic import List
    from Spotfire.Dxp.Framework.Library import *
    
    #add a script parameter lchart referring to a visualization
    chart=lchart.As[LineChart]()
    
    chart.ColorAxis.Expression = "Company"
    
    #Get Categories based on expression
    keys=List[CategoryKey]()
    keys=chart.ColorAxis.Coloring.AddCategoricalColorRule().GetExplicitCategories()
    
    #Add colors to each category
    chart.ColorAxis.Coloring.SetColorForCategory(keys[0], Color.FromName("Black"))
    chart.ColorAxis.Coloring.SetColorForCategory(keys[1], Color.FromName("Orange"))
    chart.ColorAxis.Coloring.SetColorForCategory(keys[2], Color.FromName("Blue"))
    
    #saving to Library
    folderName = "/"
    libraryManager = Document.GetService(LibraryManager)
    success, libraryFolder = libraryManager.TryGetItem(folderName, LibraryItemType.Folder)
    
    #Keywords for the colorscheme item in library
    keywords=["Red","Yellow","Green"]
    
    chart.ColorAxis.Coloring.SaveAs(libraryFolder,"testColorScheme",keywords)
     

    References

    License:  TIBCO BSD-Style License

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...