Issue using SeriesLegendSettings with ChartSeriesProvider

7 posts, 1 answers
  1. Michael
    Michael avatar
    4 posts
    Member since:
    Jul 2013

    Posted 14 Aug 2013 Link to this post

    I'm attempting to add a basic legend to go along with my dynamically generated line series:
    
    <telerik:RadCartesianChart.SeriesProvider>
       <telerik:ChartSeriesProvider Source="{Binding VisiblePortfolios}">
          <telerik:ChartSeriesProvider.SeriesDescriptors>
             <telerik:CategoricalSeriesDescriptor ItemsSourcePath="EquityCurve" ValuePath="Value" CategoryPath="Date">
                <telerik:CategoricalSeriesDescriptor.Style>
                   <Style TargetType="telerik:LineSeries">
                      <Setter Property="StrokeThickness" Value="2"/>
                      <Setter Property="LegendSettings">
                         <Setter.Value>
                            <telerik:SeriesLegendSettings Title="{Binding Name}"/>
                         </Setter.Value>
                      </Setter>
                   </Style>
                </telerik:CategoricalSeriesDescriptor.Style>
             </telerik:CategoricalSeriesDescriptor>
          </telerik:ChartSeriesProvider.SeriesDescriptors>
       </telerik:ChartSeriesProvider>
    </telerik:RadCartesianChart.SeriesProvider>

    However, this error occurs when I debug:

    System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=DataContext.Name; DataItem=null; target element is 'SeriesLegendSettings' (HashCode=10926182); target property is 'Title' (type 'String')

    And the legend does not appear at all. Any assistance is greatly appreciated.
  2. Answer
    Ves
    Admin
    Ves avatar
    2879 posts

    Posted 19 Aug 2013 Link to this post

    Hi Michael,

    Please, find attached a small example, which shows the described scenario in action with the legend appearing as expected. Please, make sure that you use the latest binaries.

    Best regards,
    Ves
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Michael
    Michael avatar
    4 posts
    Member since:
    Jul 2013

    Posted 21 Aug 2013 Link to this post

    I greatly appreciate the assistance, thank you very much for your help in solving this problem.
  5. Philip
    Philip avatar
    13 posts
    Member since:
    Mar 2015

    Posted 14 May 2015 Link to this post

    Hi, I tried the attached SeriesProviderWithLegend.

    When I run the example, the chart shows "No data to plot". However the legends displays Name1, Name2 and Name3 as expected.

    Any idea what could be wrong?

    I tried against UI for WPF Q1 2015\Binaries.NoXaml\WPF40 and Visual Studio 2013 Themes

  6. Philip
    Philip avatar
    13 posts
    Member since:
    Mar 2015

    Posted 15 May 2015 Link to this post

    I also get the following message in the output window :
    System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Name; DataItem=null; target element is 'SeriesLegendSettings' (HashCode=59586475); target property is 'Title' (type 'String')

    (I wanted to edit previous post, but seems it is not possible for a normal user. Admin, feel free to edit)
  7. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 15 May 2015 Link to this post

    Hi Philip,

    Note that when you create a custom style for any of our controls and use the NoXaml assemblies you will need to based this style to the default one. Otherwise, the default style will be overridden completely, including the template of the control, which will be empty. This is the reason why the LineSeries are not displayed. In order to resolve this you will need to set the BasedOn property with the appropriate key on the series descriptor's style. Here is an example:
    <telerik:CategoricalSeriesDescriptor.Style>
        <Style TargetType="telerik:LineSeries" BasedOn="{StaticResource LineSeriesStyle}">
            <Setter Property="StrokeThickness" Value="4"/>
            <Setter Property="Stroke" Value="Red"/>
            <Setter Property="CombineMode" Value="Stack"/>
            <Setter Property="LegendSettings">
                <Setter.Value>
                    <telerik:SeriesLegendSettings Title="{Binding Name, TargetNullValue=asdf, FallbackValue=kle}"/>
                </Setter.Value>
            </Setter>
        </Style>
    </telerik:CategoricalSeriesDescriptor.Style>

    About the error, it appears only in the output window of Visual Studio. The error will be thrown only if the CLR exception of VS are enabled. Also, the exception doesn't reflect on the application's proper work - everything works as expected. It seems that, the binding of the legend setting's Title kicks in before the DataItem is assigned and the binding is reflected a little bit later which leads to the error at the first place. However, after the DataItem is set the Title's binding getting the correct value and the legend item is generated properly. 

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. Philip
    Philip avatar
    13 posts
    Member since:
    Mar 2015

    Posted 19 May 2015 Link to this post

    Thanks, that solved the problem. This kind of binding to a dynamic list of graphs is very useful :)
Back to Top
UI for WPF is Visual Studio 2017 Ready