This is a migrated thread and some comments may be shown as answers.

Gradient in legend

1 Answer 56 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 23 Mar 2016, 09:58 PM

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.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Mar 2016, 02:10 PM
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()
    {
        base.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.
 
Regards,
Dess
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
ChartView
Asked by
Steve
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or