clone chart legend

2 posts, 0 answers
  1. Tamas
    Tamas avatar
    33 posts
    Member since:
    Jun 2010

    Posted 06 Sep 2010 Link to this post

    Hi,

    I'd like to display the legend of a RadChart out of the chart. Is this possible? I have a tabcontrol with several tabitems. There is a tabitem with a radchart on it, which is filled with data and the legend items are generated automatically. After this I'd like to display the legend of the chart in another tabitem.

    Is this possible?

    Many thanks and best regards,
    Tamás
  2. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 09 Sep 2010 Link to this post

    Hello Tamas,

    You can achieve the desired effect like this:

    XAML
    <telerik:RadTabControl Height="600" Width="800">
        <telerik:RadTabItem Header="Chart">
            <telerik:RadChart x:Name="RadChart1" >
                <telerik:RadChart.DefaultView>
                    <telerik:ChartDefaultView>
                        <telerik:ChartDefaultView.ChartArea>
                            <telerik:ChartArea Legend="{Binding ElementName=ChartLegend1}" />
                        </telerik:ChartDefaultView.ChartArea>
                        <telerik:ChartDefaultView.ChartLegend>
                            <telerik:ChartLegend Visibility="Collapsed" />
                        </telerik:ChartDefaultView.ChartLegend>
                    </telerik:ChartDefaultView>
                </telerik:RadChart.DefaultView>
            </telerik:RadChart>
        </telerik:RadTabItem>
        <telerik:RadTabItem Header="Legend">
            <telerik:ChartLegend x:Name="ChartLegend1" />
        </telerik:RadTabItem>
    </telerik:RadTabControl>

    C#
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
     
            Random rand = new Random(123456);
            List<ChartData> data = new List<ChartData>();
            for (int i = 0; i < 10; i++)
                data.Add(new ChartData() { XValue = i, YValue = rand.Next(10, 100) });
     
            SeriesMapping sm = new SeriesMapping();
            sm.ItemMappings.Add(new ItemMapping("XValue", DataPointMember.XValue));
            sm.ItemMappings.Add(new ItemMapping("YValue", DataPointMember.YValue));
     
            RadChart1.SeriesMappings.Add(sm);
            RadChart1.DefaultSeriesDefinition = new DoughnutSeriesDefinition();
            RadChart1.ItemsSource = data;
        }
    }
     
    public class ChartData
    {
        public double YValue
        {
            get;
            set;
        }
     
        public double XValue
        {
            get;
            set;
        }
    }


    Hope this helps.


    Kind regards,
    Freddie
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top