LegendLabel Bind Problem.

3 posts, 0 answers
  1. Muhammad Irfan
    Muhammad Irfan avatar
    18 posts
    Member since:
    Jan 2010

    Posted 02 Dec 2011 Link to this post

    We are tying two bind Chart Series dynamically based on selected cell of above grid. Everything is working fine except LegendLabel is coming "Series0" and Series1. I see here that legend label is coming right if we bind our viewmodel statically in xaml but if we assign viewmodel as DataContext through code then legend label does not work.
    Here is my code how I am doing.

    MacroVal.MacroValCoorelation view = new MacroVal.MacroValCoorelation();
                    view.DataContext = new MacroVal.MacroValCoorelationViewModel(processor);  //here I have to pass one input parameter in view model

    Now my chart on view is like this
    <telerik:RadChart Name="radChart1" ItemsSource="{Binding CorrelationChartData}" Grid.Row="2" BorderThickness="0" BorderBrush="Transparent">
                    <telerik:SamplingSettings SamplingThreshold="400" />
                    <telerik:ChartDefaultView ChartLegendPosition="Bottom">
                            <telerik:ChartLegend x:Name="chartLegend" Header="" UseAutoGeneratedItems="True" Background="Transparent" BorderThickness="0">
                            <telerik:ChartArea LegendName="chartLegend">
                                    <telerik:AxisX DefaultLabelFormat="M/d/yy" LabelRotationAngle="90">
                    <telerik:SeriesMapping LegendLabel="{Binding CurrentIndicatorName}">
                            <telerik:LineSeriesDefinition ShowItemLabels="False" ShowPointMarks="False" LegendDisplayMode="SeriesLabel">
                            <telerik:ItemMapping DataPointMember="XValue"
                                               FieldName="Date" />
                            <telerik:ItemMapping DataPointMember="YValue"
                                               FieldName="Value1" />
                    <telerik:SeriesMapping LegendLabel="{Binding PreIndicatorName}">
                            <telerik:LineSeriesDefinition ShowItemLabels="False" ShowPointMarks="False" LegendDisplayMode="SeriesLabel" />
                            <telerik:ItemMapping DataPointMember="XValue"
                                               FieldName="Date" />
                            <telerik:ItemMapping DataPointMember="YValue"
                                               FieldName="Value2" />

    And here is my ViewModel Properties.

    public List<LOB.DateValuesChartData> CorrelationChartData
                    return _ChartData;
            public string CurrentIndicatorName { get { return _CurIndicatorName; } }
            public string PreIndicatorName { get { return _PrevIndicatorName; } }
  2. Imran Javed Zia
    Imran Javed  Zia avatar
    55 posts
    Member since:
    Jul 2009

    Posted 02 Dec 2011 Link to this post

    We also have similar issue that, when we bind the chart with two series dynamically, then how can we change the related Legends Labels?Thanks
  3. Ves
    Ves avatar
    2914 posts

    Posted 06 Dec 2011 Link to this post


    Please, find attached an example, showing how to achieve the desired result. It uses the DataBound event of RadChart to populate the LegendLabel property.

    Best regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top