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

Change LegendLabel in Code behine

2 Answers 89 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.
Abdulhameed
Top achievements
Rank 1
Abdulhameed asked on 10 Apr 2012, 06:29 AM
I have a chart with three Series Mapping two lines, and one area chart, for the legend I am using auto generated items and setting the label on the series mapping. see the code below

<telerik:RadChart HorizontalAlignment="Left" telerik:StyleManager.Theme="Metro"
                          Name="SeisLineChart" VerticalAlignment="Top"
                          ItemsSource="{Binding}"  Height="500" Width="700" Margin="0">
            <telerik:RadChart.DefaultView>
                <telerik:ChartDefaultView ChartLegendPosition="Bottom">
                    <!--<telerik:ChartDefaultView.ChartTitle>
                        <telerik:ChartTitle FontSize="13" Padding="2" />
                    </telerik:ChartDefaultView.ChartTitle>-->
                    <telerik:ChartDefaultView.ChartLegend>
                        <telerik:ChartLegend x:Name="DailyProductionRefLegend" Header="" UseAutoGeneratedItems="True"  Padding="2,2,5,1" HorizontalAlignment="Center" HorizontalContentAlignment="Center"/>
                    </telerik:ChartDefaultView.ChartLegend>
                    <telerik:ChartDefaultView.ChartArea>
                        <telerik:ChartArea Grid.Row="1" Grid.RowSpan="2" x:Name="chartArea" LegendName="DailyProductionRefLegend" >
                            <telerik:ChartArea.AxisY>
                                <telerik:AxisY x:Name="yAxis" Title="Unit" AutoRange="True" DefaultLabelFormat="#VAL{###,###}"/>
                            </telerik:ChartArea.AxisY>
                            <telerik:ChartArea.AxisX>
                                <telerik:AxisX x:Name="xAxis" Title="Weeks" AutoRange="True" LabelStep="4" IsDateTime="False"/>
                            </telerik:ChartArea.AxisX>
                             
                        </telerik:ChartArea>
                    </telerik:ChartDefaultView.ChartArea>
                </telerik:ChartDefaultView>
            </telerik:RadChart.DefaultView>
            <telerik:RadChart.SeriesMappings>
                <telerik:SeriesMapping x:Name="FiveYearsRangeMapping" LegendLabel="5 Year Ranges">
                    <telerik:SeriesMapping.SeriesDefinition>
                        <telerik:RangeSeriesDefinition SeriesName="FiveYearsRange" ShowItemLabels="False" 
                                                      ShowItemToolTips="True"
                                                      ShowPointMarks="False"
                                                             EmptyPointBehavior="Zero"/>
                    </telerik:SeriesMapping.SeriesDefinition>
                    <telerik:SeriesMapping.ItemMappings>
                        <telerik:ItemMapping DataPointMember="XCategory"  FieldName="Week" />
                        <telerik:ItemMapping DataPointMember="High" FieldName="HighValue" />
                        <telerik:ItemMapping DataPointMember="Low" FieldName="LowValue" />
                    </telerik:SeriesMapping.ItemMappings>
                </telerik:SeriesMapping>
 
                <telerik:SeriesMapping x:Name="LastYearMapping" LegendLabel="Last Year">
                    <telerik:SeriesMapping.SeriesDefinition>
                        <!--<telerik:SplineSeriesDefinition ShowItemLabels="False"  ShowItemToolTips="True" ItemToolTipFormat="#DATAITEM.Quantity{###,###,##0} #DATAITEM.UnitCode"/>-->
                        <telerik:LineSeriesDefinition SeriesName="LastYear" ShowItemLabels="False" 
                                                      ShowItemToolTips="True"
                                                      ShowPointMarks="False"
                                                             EmptyPointBehavior="Gap"
                                                      />
 
                    </telerik:SeriesMapping.SeriesDefinition>
                    <!--<telerik:SeriesMapping.GroupingSettings>
                        <telerik:GroupingSettings ShouldCreateSeriesForLastGroup="True">
                            <telerik:GroupingSettings.GroupDescriptors>
                                <telerik:ChartGroupDescriptor Member="Product"/>
                            </telerik:GroupingSettings.GroupDescriptors>
                        </telerik:GroupingSettings>
                    </telerik:SeriesMapping.GroupingSettings>-->
                    <telerik:SeriesMapping.ItemMappings>
                        <telerik:ItemMapping DataPointMember="XCategory"  FieldName="Week" />
                        <telerik:ItemMapping DataPointMember="YValue" FieldName="LastYearQ" />
                    </telerik:SeriesMapping.ItemMappings>
                </telerik:SeriesMapping>
 
                <telerik:SeriesMapping x:Name="CurrentYearMapping" LegendLabel="Current Year">
                    <telerik:SeriesMapping.SeriesDefinition>
                        <telerik:LineSeriesDefinition SeriesName="CurrentYear" ShowItemLabels="False" 
                                                      ShowItemToolTips="True"
                                                      ShowPointMarks="False"
                                                             EmptyPointBehavior="Gap"/>
                    </telerik:SeriesMapping.SeriesDefinition>
                    <telerik:SeriesMapping.ItemMappings>
                        <telerik:ItemMapping DataPointMember="XCategory"  FieldName="Week" />
                        <telerik:ItemMapping DataPointMember="YValue" FieldName="CurrentYeatQ" />
                    </telerik:SeriesMapping.ItemMappings>
                </telerik:SeriesMapping>
 
                 
            </telerik:RadChart.SeriesMappings>
 
        </telerik:RadChart>


However when I tired to change the legend label from code behind it didn't work
SeisLineChart.SeriesMappings[0].LegendLabel = "New Legend label";


What is the best way yo change the legend label from code behind?

2 Answers, 1 is accepted

Sort by
0
Peshito
Telerik team
answered on 12 Apr 2012, 11:04 AM
Hello Abdulhameed,

The way you are setting the LegendLabel in code behind is the correct one, however I was not able to reproduce the issue you have described. Please, find attached a sample project with a scenario similar to yours. If it does not help you solve your issue, could you send us a small runnable project isolating the problem, so we could provide you with an appropriate solution.

Regards,
Peshito
the Telerik team

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

0
Abdulhameed
Top achievements
Rank 1
answered on 14 Apr 2012, 07:15 AM
The attached project didn't load properly.

However I figured it out, the below code worked fine
((DataSeriesCollection)SeisLineChart.DefaultView.ChartArea.DataSeries)[1].LegendLabel = "Last Year, 2011 ";
Tags
Chart
Asked by
Abdulhameed
Top achievements
Rank 1
Answers by
Peshito
Telerik team
Abdulhameed
Top achievements
Rank 1
Share this question
or