Detach chart legend

2 posts, 0 answers
  1. Andy H
    Andy H avatar
    12 posts
    Member since:
    Oct 2009

    Posted 04 Apr 2011 Link to this post

    I am trying to detach my legend from the DefaultView. Following the post by Manol, I was able to get the desired behaviour, but only when defined in XAML. Using the code below, the legend is shown, but never populated. 

    var stackPanel = new StackPanel { OrientationOrientation = Orientation.Horizontal };
    var legendName = "MyLegend"
    var chartLegend = new ChartLegend { Name = legendName }; 
    var radChart = new RadChart(); 
    radChart.DefaultView.ChartLegend.Visibility = Visibility.Collapsed; 
    radChart.DefaultView.ChartArea.LegendName = legendName; 

    This is the XAML, which actually works:
    <StackPanel Name="LayoutRoot" Orientation="Horizontal">
        <telerik:RadChart Name="rcChart">
                        <telerikCharting:ChartLegend Visibility="Collapsed" />
                        <telerikCharting:ChartArea LegendName="MyLegend" />
        <telerikCharting:ChartLegend Name="MyLegend"></telerikCharting:ChartLegend>

    Any ideas?
  2. Giuseppe
    Giuseppe avatar
    2363 posts

    Posted 04 Apr 2011 Link to this post

    Hi Andy H,

    In code behind you can associate the ChartArea and the ChartLegend via the ChartArea.Legend property like this:

    var stackPanel = new StackPanel { Orientation = Orientation.Horizontal };
    var chartLegend = new ChartLegend();
    var radChart = new RadChart();
    radChart.DefaultView.ChartLegend.Visibility = Visibility.Collapsed;
    radChart.DefaultView.ChartArea.Legend = chartLegend;

    Best wishes,
    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