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

[Solved] Getting rid of the legend

3 Answers 171 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.
Steve
Top achievements
Rank 1
Steve asked on 15 Jul 2011, 03:15 PM
Hi there.

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

Sort by
0
Sia
Telerik team
answered on 19 Jul 2011, 08:28 AM
Hi John,

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!

0
Steve
Top achievements
Rank 1
answered on 19 Jul 2011, 04:49 PM
I'm afraid that's not working for me.

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?

0
Sia
Telerik team
answered on 21 Jul 2011, 03:33 PM
Hi John,

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!

Tags
Chart
Asked by
Steve
Top achievements
Rank 1
Answers by
Sia
Telerik team
Steve
Top achievements
Rank 1
Share this question
or