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
    view.showDialog()

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

    And here is my ViewModel Properties.

    public List<LOB.DateValuesChartData> CorrelationChartData
            {
                get
                {
                    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

    Hi,
    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. UI for WPF is Visual Studio 2017 Ready
  4. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 06 Dec 2011 Link to this post

    Hello,

    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,
    Ves
    the Telerik team

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

Back to Top