Problems adding CartesianGridLineAnnotation to RadCartesianChart in XAML

4 posts, 0 answers
  1. Andrew
    Andrew avatar
    37 posts
    Member since:
    Dec 2012

    Posted 21 Aug 2014 Link to this post

    I'm having problems adding CartesianGridLineAnnotations to my RadCartesianCharts. I've read the documentation on this page : http://www.telerik.com/help/wpf/radchartview-annotations-gridline.html and followed the example answer given in this forum post : http://www.telerik.com/forums/cartesian-chart-without-adding-new-axis-for-custom-line but whenever I try to add the annotation I get an error. 

    In the forum post you give the following example: 

    [code]
    <telerik:RadCartesianChart x:Name="chart">
       <telerik:RadCartesianChart.VerticalAxis>
          <telerik:LinearAxis />
       </telerik:RadCartesianChart.VerticalAxis>
       <telerik:RadCartesianChart.Annotations>
       <telerik:CartesianGridLineAnnotation Axis="{Binding ElementName=chart, Path=VerticalAxis}" Value="25" />
    [/code]

    Which sets up the chart and axis, then adds the CartesianGridLineAnnotation, binding the Axis value to ther VerticalAxis in the element named "chart." 

    My code is as follows:

    [code]
    <telerik:RadCartesianChart x:Name="SummaryChart" UseLayoutRounding="True" Grid.Row="1" TooltipTemplate="{Template}">
       <telerik:RadCartesianChart.HorizontalAxis>
          <telerik:CategoricalAxis LabelFitMode="Rotate" />
       </telerik:RadCartesianChart.HorizontalAxis>
                                                  
       <telerik:RadCartesianChart.VerticalAxis>
          <telerik:LinearAxis />
       </telerik:RadCartesianChart.VerticalAxis>
                                                  
       <telerik:RadCartesianChart.Annotations>
          <telerik:CartesianGridLineAnnotation Axis="{Binding ElementName=SummaryChart, Path=VerticalAxis}" Value="6" Stroke="Red" StrokeThickness="1"/>
       </telerik:RadCartesianChart.Annotations>
    [/code]

    As far as I can tell this is following your example of how to bind to the Vertical axis. 

    However when I use this XAML I get the following binding error:

    System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=SummaryChart'. BindingExpression:Path=VerticalAxis; DataItem=null; target element is 'CartesianGridLineAnnotation' (Name=''); target property is 'Axis' (type 'CartesianAxis')

    Do you know what I'm doing wrong? 

    Thanks,

    Andy.






  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 22 Aug 2014 Link to this post

    Hi Andy,

    Your code looks correct. I tested it and it works as expected, this is why I am attaching the test project. Can you please take a look at it and let me know if I am missing something? 

    You can try to delete the "bin" and "obj" folders from your project's directory and then Clean and Rebuild the solution or you can try to bind the Axis property of the annotation directly to the  axis.

    <telerik:RadCartesianChart x:Name="SummaryChart" UseLayoutRounding="True" Grid.Row="1">
        ...
        <telerik:RadCartesianChart.VerticalAxis>
            <telerik:LinearAxis x:Name="axis"/>
        </telerik:RadCartesianChart.VerticalAxis>
        ....
        <telerik:RadCartesianChart.Annotations>
            <telerik:CartesianGridLineAnnotation Axis="{Binding ElementName=axis}" Value="6" Stroke="Red" StrokeThickness="1"/>
        </telerik:RadCartesianChart.Annotations>
    </telerik:RadCartesianChart>

    Thank you for any help you can provide.

    Regards,
    Martin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Andrew
    Andrew avatar
    37 posts
    Member since:
    Dec 2012

    Posted 22 Aug 2014 in reply to Martin Link to this post

    Hi Martin, thanks for the response. 

    Your demo program works perfectly and appears to be using the same method I am. I tried your suggestion of binding directly to the named axis but encountered the same problem. 

    Something I should have mentioned before is that this is a box whisker chart and data is being added to this chart through a series provider with a line series overlaid. Would this affect the annotation? 

    Thanks again,

    Ewan.
  5. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 27 Aug 2014 Link to this post

    Hello Andew,

    No, using the SeriesProvider should not affect the annotation. Can you please send us a sample project that isolates the reported error? This way we will be able to test it on our side and investigate what is causing the issue.

    Thank you for any help you can provide.

    Regards,
    Martin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top