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; 
       
    stackPanel.Children.Add(radChart); 
    stackPanel.Children.Add(chartLegend);

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

    Any ideas?
  2. Giuseppe
    Admin
    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;
     
    stackPanel.Children.Add(radChart);
    stackPanel.Children.Add(chartLegend);
     
    LayoutRoot.Children.Add(stackPanel);



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