Problem with ChartSeriesProvider and LegendSettings

3 posts, 1 answers
  1. Renier Pretorius
    Renier Pretorius avatar
    46 posts
    Member since:
    Apr 2010

    Posted 11 May Link to this post

    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. Answer
    Ivan
    Admin
    Ivan avatar
    44 posts

    Posted 12 May Link to this post

    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.
  3. DevCraft banner
  4. Renier Pretorius
    Renier Pretorius avatar
    46 posts
    Member since:
    Apr 2010

    Posted 12 May in reply to Ivan Link to this post

    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

Back to Top