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
- API Reference: Visual
- API Reference: Coloring
- API Reference: Categorical Color Rule
- API Reference: CategoryKey
License: TIBCO BSD-Style License
Recommended Comments
There are no comments to display.