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

Pie Chart Legend

1 Answer 44 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Joan
Top achievements
Rank 1
Joan asked on 08 Mar 2012, 05:51 AM
Is it possible to add an extra item to a pie chart legend with the new item as the last one?  I can add an the extra item, but it always appears first.

1 Answer, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 12 Mar 2012, 10:16 AM
Hello Joan,

You can achieve the desired effect by adding the custom legend item in the RadChart.BeforeLayout event handler like this:
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ChartSeries series1 = new ChartSeries();
 
        if (!IsPostBack)
        {
            ChartSeries series = new ChartSeries() { Type = ChartSeriesType.Pie };
            series.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;
            series.Items.Add(new ChartSeriesItem(20) { Name = "Test 1" });
            series.Items.Add(new ChartSeriesItem(40) { Name = "Test 2" });
            series.Items.Add(new ChartSeriesItem(60) { Name = "Test 3" });
 
            radChart.Series.Add(series);
            radChart.BeforeLayout += this.radChart_BeforeLayout;
        }
    }
 
    private void radChart_BeforeLayout(object sender, EventArgs e)
    {
        var style = new FillStyle();
        style.MainColor = Color.Red;
        style.FillType = FillType.Solid;
 
        radChart.Legend.AddCustomItemToLegend("Custom", style, DefaultFigures.Cross);
    }
}

Hope this helps.


Kind regards,
Giuseppe
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Chart (Obsolete)
Asked by
Joan
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Share this question
or