Jump to content
We've recently updated our Privacy Statement, available here. ×
  • How to Retrieve and Set Colors from a Categorical Axis on a Visualization Using the Spotfire® C# API


    The following is a sample C# code which illustrates how to retrieve and set a color for a specific category on a categorical axis, for a Line Chart visualization.

    Introduction

    The following is a sample C# code which illustrates how to retrieve and set a color for a specific category on a categorical axis, for a Line Chart visualization:

    Code Sample

    // Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license.
    
    public static void someMethodName(AnalysisApplication application)
    {
        LineChart lc = application.Document.ActiveVisualReference.As<LineChart>();
    
        //Retrieve colors of a specific category
        int count = lc.ColorAxis.Coloring.AddCategoricalColorRule().GetExplicitCategories().Count;    
        IList<CategoryKey> myKeys = lc.ColorAxis.Coloring.AddCategoricalColorRule().GetExplicitCategories();    
        List<string> categoryKeyNames = new List<string>();
        List<string> colors = new List<string>();
        foreach (CategoryKey key in myKeys)
        {
    	categoryKeyNames.Add(key.ToString());
            colors.Add(lc.ColorAxis.Coloring.GetColorForCategory(key).ToString());
        }
        MessageBox.Show("number of categories found:" + count + "n categories:" + categoryKeyNames[0] + "-" + colors[0]);
        
    	//Set color for a specific category
        string hexValue = "#DAA520"; // You do need the hash, [goldenrod color] 
        System.Drawing.Color colour = System.Drawing.ColorTranslator.FromHtml(hexValue);
        lc.ColorAxis.Coloring.SetColorForCategory(myKeys[1], colour);           
    }
     

    References

    License:  TIBCO BSD-Style License

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...