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

Problem with ChartSeriesProvider and LegendSettings

2 Answers 180 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Renier Pretorius
Top achievements
Rank 2
Iron
Iron
Iron
Renier Pretorius asked on 11 May 2016, 12:55 PM

Hi,

I have a chartview with dynamic number of series. I am setting the LegendSettings property on the SeriesDescriptor.Style. The approach worked fine in WPF, but now I am transferring it to Silverlight and for some reason the LegendItem Title property does not want to bind to the series source.

<telerik:RadCartesianChart.SeriesProvider>
    <telerik:ChartSeriesProvider Source="{Binding SectionDemandAtoB}">
        <telerik:ChartSeriesProvider.SeriesDescriptors>
 
            <telerik:CategoricalSeriesDescriptor ItemsSourcePath="SeriesData" ValuePath="Value" CategoryPath="Category">
                <telerik:CategoricalSeriesDescriptor.Style>
                    <Style TargetType="telerik:BarSeries" BasedOn="{StaticResource BarSeriesStyle}">
                        <Setter Property="CombineMode" Value="Stack" />
                        <Setter Property="DisplayName" Value="{Binding SeriesLabel}" />
                        <Setter Property="LegendSettings">
                            <Setter.Value>
                                <telerik:SeriesLegendSettings Title="{Binding SeriesLabel, Converter={StaticResource debugConverter}, FallbackValue='No Series Label'}" />
                            </Setter.Value>
                        </Setter>
                        <Setter Property="DefaultVisualStyle">
                            <Setter.Value>
                                <Style TargetType="Border">
                                    <!--<Setter Property="Background" Value="Red"/>-->
                                    <Setter Property="Background" Value="{Binding DataItem.ColorString}"/>
                                </Style>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </telerik:CategoricalSeriesDescriptor.Style>
            </telerik:CategoricalSeriesDescriptor>
 
        </telerik:ChartSeriesProvider.SeriesDescriptors>
    </telerik:ChartSeriesProvider>
 
</telerik:RadCartesianChart.SeriesProvider>

The DisplayName on the series does get set correctly as the tooltip works fine. However, the debugConverter does not even get hit and it defaults to the fallbackvalue. Am I missing something?

PS: using v.2016.1.112.1050 Dev

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan
Telerik team
answered on 12 May 2016, 01:12 PM
Hi Renier,

There is a limitation in Silverlight regarding the this binding in a SeriesProvider scenario.

However, there is an easy workaround you can use. Please refer to the following code snippet.
<telerik:CategoricalSeriesDescriptor.Style>
    <Style TargetType="telerik:BarSeries">
       <Setter Property="CombineMode" Value="Stack" />
       <Setter Property="DisplayName" Value="{Binding SeriesLabel}" />
       <Setter Property="LegendSettings" Value="{Binding Converter={StaticResource titleConverter}}" />
public class LabelConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
SeriesCollection collection = value as SeriesCollection;
 
return new SeriesLegendSettings() { Title = collection.SeriesLabel.ToString() };
}
For a sample implementation of this approach you can take a look the attached project. Let us know if it works for you.

Regards,
Ivan
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Renier Pretorius
Top achievements
Rank 2
Iron
Iron
Iron
answered on 12 May 2016, 06:58 PM

Hi Ivan,

Thanks. That worked perfectly. My work around involved handling the SeriesCreated event and then setting the LegendSettings for the series explicitly by matching the index in the chart series collection to the index of the business object in the view model collection. This is obviously much cleaner and more reuseable.

Regards

Renier

Tags
ChartView
Asked by
Renier Pretorius
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Ivan
Telerik team
Renier Pretorius
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or