Gradient in legend

2 posts, 0 answers
  1. Steve
    Steve avatar
    43 posts
    Member since:
    May 2014

    Posted 23 Mar Link to this post

    I have a series where I am using the "LabelFormatting" event to color scatter points individually, and I would like to paint the legend item as a gradient to reflect that is not a single color but I cannot tell how to accomplish it. I am also using something I saw in the forums for adding checkboxes to the legend via handling the VisualItemCreating and replacing with my own derived LegendItemElement. After creating the child elements I am looking at the legend item marker and I see a lot of properties for gradients but no way to activate them.


    I've also tried setting the BackColor and BackColor2 of the series, as well as NumberOfColors = 2 with no effect.

  2. Dess
    Dess avatar
    1561 posts

    Posted 24 Mar Link to this post

    Hello Steve,

    Thank you for writing.

    Please refer to the following code snippet demonstrating how to achieve gradient in the LegendItemElement.MarkerElement:
    private void LegendElement_VisualItemCreating(object sender, LegendItemElementCreatingEventArgs e)
        e.ItemElement = new CustomLegendItemElement(e.LegendItem);
    public class CustomLegendItemElement : LegendItemElement
        public CustomLegendItemElement(LegendItem item) : base(item)
        protected override void Synchronize()
            this.MarkerElement.DrawFill = true;
            this.MarkerElement.GradientStyle = GradientStyles.Linear;
            this.MarkerElement.BackColor = Color.Red;
            this.MarkerElement.BackColor2 = Color.Blue;
            this.MarkerElement.BackColor3 = Color.Yellow;
            this.MarkerElement.BackColor4 = Color.Pink;
            this.MarkerElement.BackgroundShape = null;
            this.MarkerElement.NumberOfColors = 4;
            this.MarkerElement.DrawBorder = false;

    I hope this information helps. Should you have further questions I would be glad to help.
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. DevCraft banner
Back to Top