Jump to content
  • How to apply ColoringScheme from one Visualization to another in Spotfire® Using IronPython Scripting


    Below is a sample script on how to read a coloring scheme of one visualization , save it to library and apply it to another visualization

    Introduction

    Below is a sample script on how to read a coloring scheme of one visualization , save it to library and apply it to another visualization

    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 schart referring to a visualization 
    chart=schart.As[ScatterPlot]() 
    
    #saving to Library 
    folderName = "/myFolder" 
    libraryManager = Document.GetService(LibraryManager) 
    success, libraryFolder = libraryManager.TryGetItem(folderName, LibraryItemType.Folder) 
    colorSchemeLibraryItem=chart.ColorAxis.Coloring.SaveAs(libraryFolder,"colorSchemeName",["KeyWords"]) 
    
    #Delete the coloring scheme from Document in order to overide with the new coloring scheme saved to library with any changes
    coloringTemplatesCollection=Document.ColoringTemplates
    for index,colorSchemeName in enumerate(coloringTemplatesCollection):
        if colorSchemeName.DisplayName=="colorSchemeName":
            coloringTemplatesCollection.RemoveAt(index)
        
    #add the coloring scheme to document
    coloring=coloringTemplatesCollection.AddFromLibrary(colorSchemeLibraryItem)
    coloring.DisplayName="colorSchemeName"
    
    #viz is an input parameter, referenced to the visualization where Color Scheme needs to be applied. 
    vis = vizA.As[LineChart]() 
    vis.ColorAxis.Expression = "expression"
    vis.ColorAxis.Coloring.Apply("colorSchemeName") #ColorSchemeName should be stored in the document or library.
     

    References

    License:  TIBCO BSD-Style License

    Back to IronPython Scripting in TIBCO Spotfire Examples:  https://community.spotfire.com/s/article/IronPython-Scripting-in-Spotfire

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...