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

Detach chart legend

1 Answer 103 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andy H
Top achievements
Rank 1
Andy H asked on 04 Apr 2011, 12:45 PM
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?

1 Answer, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 04 Apr 2011, 04:52 PM
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
Tags
Chart
Asked by
Andy H
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Share this question
or