Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
575
How to Change legend color based on legend text
posted

Hi 

 

How Could i change the Legend small boxes colors based on thier labels 

i have change my pie chart slices based on the labels but i need to change the legend to reflect my color changes 

 

Hope to help me.. and thanks alot

 

  • 28496
    Verified Answer
    Offline posted

    private void ultraChart1_FillSceneGraph(object sender, FillSceneGraphEventArgs e)
            {
                for (int current = 0; current < e.SceneGraph.Count; current++)
                {
                    Box currentBox = e.SceneGraph[current] as Box;
                    if (currentBox != null && currentBox.Path != null && currentBox.Path.Contains("Legend"))
                    {
                        // legend box
                        Text label = e.SceneGraph[current + 1] as Text;
                        if (label != null)
                        {
                            switch (label.GetTextString())
                            {
                                case "ROW #1":
                                    currentBox.PE = new PaintElement(Color.Pink);
                                    break;
                                case "ROW #2":
                                    currentBox.PE = new PaintElement(Color.Lime);
                                    break;
                            }
                        }
                    }
                }
            }