I've been through the online help and haven't been able to find an answer to this one so far as I can tell. I just want to get rid of the legend bar from my chart. It takes up quite a lot of space!
Thanks.
3 Answers, 1 is accepted
You need to collapse it. Please check this example for reference.
Here is a code snippet:
<telerik:ChartDefaultView> <telerik:ChartDefaultView.ChartArea> <telerik:ChartArea LegendName="PrimaryLegend"> <telerik:ChartArea.AxisY> <telerik:AxisY Title="GDP (in million USD)" /> </telerik:ChartArea.AxisY> </telerik:ChartArea> </telerik:ChartDefaultView.ChartArea> <telerik:ChartDefaultView.ChartLegend> <telerik:ChartLegend x:Name="PrimaryLegend" Visibility="Collapsed" /> </telerik:ChartDefaultView.ChartLegend></telerik:ChartDefaultView>Kind regards,
Sia
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
Here's the code from before:
XAML:
<telerikChart:RadChart x:Name="RadChart" Grid.Row="1" Margin="5,5,5,5" Background="#EEC1E8F2" />
And then after:
<telerikChart:RadChart x:Name="RadChart" Grid.Row="1" Margin="5,5,5,5" Background="#EEC1E8F2"> <telerik:ChartDefaultView> <telerik:ChartDefaultView.ChartArea><telerik:ChartArea LegendName="PrimaryLegend"><telerik:ChartArea.AxisY><telerik:AxisY Title="GDP (in million USD)"/></telerik:ChartArea.AxisY></telerik:ChartArea></telerik:ChartDefaultView.ChartArea> <telerik:ChartDefaultView.ChartLegend><telerik:ChartLegend x:Name="PrimaryLegend" Visibility="Collapsed"/></telerik:ChartDefaultView.ChartLegend></telerik:ChartDefaultView></telerikChart:RadChart>
Within this there is some code in the view model:
SeriesMapping
smapping = new SeriesMapping();
smapping.LegendLabel =
"Publishing thingy";
smapping.SeriesDefinition =
new BarSeriesDefinition();
smapping.ItemMappings.Add(
new ItemMapping("Month", DataPointMember.XValue));
smapping.ItemMappings.Add(
new ItemMapping("Quantity", DataPointMember.YValue));
smapping.ItemMappings.Add(
new ItemMapping("MonthName", DataPointMember.XCategory));
PublishingChart.SeriesMappings.Add(smapping);
PublishingChart.ItemsSource =
this.PopulateData();
That said, I tried removing the code in the view model to see if it made a difference - it did not. All I can say for sure is that the legend bar on the chart is still very much there.
I include two pictures. One is how the graph looks in the first instance (before I added the XAML you suggested). This is called 'without additional XAML.jpg'. The second image shows the chart with the additional XAML. This is called 'with additional XAML.jpg'. As far as I can see, the only difference is some text in the top left corner.
Perhaps you can offer some suggestions?
Your mistake was difficult for finding :) I am sorry for misleading you with my code snippet.
Here is what you need to add in your XAML:
<telerik:RadChart x:Name="RadChart" Margin="5,5,5,5" Background="#EEC1E8F2"> <telerik:RadChart.DefaultView> <telerik:ChartDefaultView> <telerik:ChartDefaultView.ChartArea> <telerik:ChartArea LegendName="legend"> <telerik:ChartArea.AxisY> <telerik:AxisY Title="GDP (in million USD)"/> </telerik:ChartArea.AxisY> </telerik:ChartArea> </telerik:ChartDefaultView.ChartArea> <telerik:ChartDefaultView.ChartLegend> <telerik:ChartLegend x:Name="legend" Visibility="Collapsed" /> </telerik:ChartDefaultView.ChartLegend> </telerik:ChartDefaultView> </telerik:RadChart.DefaultView></telerik:RadChart>You can hide your Legend in code-behind also (then you won't need any additional XAML):
RadChart.DefaultView.ChartLegend.Visibility = System.Windows.Visibility.Collapsed;Regards,
Sia
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!