This is a migrated thread and some comments may be shown as answers.
Problems adding CartesianGridLineAnnotation to RadCartesianChart in XAML
3 Answers 73 Views
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 21 Aug 2014, 09:05 AM
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.






3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 22 Aug 2014, 08:30 AM
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.
 
0
Andrew
Top achievements
Rank 1
answered on 22 Aug 2014, 03:37 PM
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.
0
Martin Ivanov
Telerik team
answered on 27 Aug 2014, 11:25 AM
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.
 
Asked by
Andrew
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or