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

Chart Legend is missing

2 Answers 99 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Liberte
Top achievements
Rank 1
Liberte asked on 20 Jul 2009, 03:05 PM
Hello guys, i have that lines in my code-behind:
public partial class MainWindow : Window 
    { 
        public MainWindow() 
        { 
            this.InitializeComponent(); 
            MainWindowViewModel model = new MainWindowViewModel(); 
            RadChart1.DefaultView.ChartArea = model.MainChartArea; 
            RadChart1.DefaultView.ChartLegend.UseAutoGeneratedItems = true
        }         
    } 
    public class MainWindowViewModel 
    { 
        private ChartArea _area; 
        public ChartArea MainChartArea 
        { 
            get  
            { 
                if (_area == null
                    _area = CreateChartArea(); 
                return _area; 
            } 
        }         
        private ChartArea CreateChartArea() 
        { 
            ChartArea area = new ChartArea(); 
 
            DataSeries ser1 = new DataSeries(); 
            ser1.Add(new DataPoint(23)); 
            ser1.Add(new DataPoint(45)); 
            ser1.Add(new DataPoint(33)); 
            ser1.Add(new DataPoint(12)); 
            ser1.Add(new DataPoint(50)); 
            ser1.LegendLabel = "Series 1 Label"
            area.DataSeries.Add(ser1); 
 
            DataSeries ser2 = new DataSeries(); 
            ser2.Add(new DataPoint(45)); 
            ser2.Add(new DataPoint(50)); 
            ser2.Add(new DataPoint(60)); 
            ser2.Add(new DataPoint(30)); 
            ser2.Add(new DataPoint(25)); 
            ser2.LegendLabel = "Series 2 Label"
            area.DataSeries.Add(ser2); 
 
            return area; 
        } 
    } 
and that is the XAML part:
<Grid x:Name="LayoutRoot"
        <control:RadChart x:Name="RadChart1"
            <control:RadChart.DefaultView> 
                <chart:ChartDefaultView> 
                     
                    <chart:ChartDefaultView.ChartLegend> 
                        <chart:ChartLegend x:Name="CustomLegend" Header="Legend Header" UseAutoGeneratedItems="True"
                        </chart:ChartLegend> 
                    </chart:ChartDefaultView.ChartLegend> 
                    <chart:ChartDefaultView.ChartTitle> 
                        <chart:ChartTitle> 
                            <TextBlock Text="Declarative RadChart"/> 
                        </chart:ChartTitle> 
                    </chart:ChartDefaultView.ChartTitle> 
                </chart:ChartDefaultView> 
            </control:RadChart.DefaultView> 
        </control:RadChart> 
 
    </Grid> 
but now... i don't have the Legend generated. So what's missing? How to get back the Legend if i use something like MVVM?


2 Answers, 1 is accepted

Sort by
0
Accepted
Giuseppe
Telerik team
answered on 23 Jul 2009, 07:30 AM
Hi Liberte,

You need to explicitly associate the ChartArea and the ChartLegend in this scenario as you are swapping the default ChartArea instance:

public Window1() 
    this.InitializeComponent(); 
    MainWindowViewModel model = new MainWindowViewModel(); 
    model.MainChartArea.Legend = RadChart1.DefaultView.ChartLegend; 
    RadChart1.DefaultView.ChartArea = model.MainChartArea; 
    RadChart1.DefaultView.ChartLegend.UseAutoGeneratedItems = true



Regards,
Manuel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Liberte
Top achievements
Rank 1
answered on 24 Jul 2009, 10:40 AM
Oh, yes .. that makes sense. Thanks :}
Tags
Chart
Asked by
Liberte
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Liberte
Top achievements
Rank 1
Share this question
or