I'm trying to use the annotations. my x axis is date time.
When i try to add CartesianGridLineAnnotation i get the following error:
: The value: '0' provided for the annotation is incompatible with the selected axis.
When I try to add CartesianPlotBandAnnotation my content page is not loaded
when i tried to add CartesianPlotBandAnnotation to axis y which is numeric it worked fine.
Any suggestions? the annotations feature is crucial for my chart implementation.
4 Answers, 1 is accepted
I have just tried setting GridLineAnnotation with DateTimeContinousAxis like this:
and the annotation is displayed without a problem. Please have in mind that the Annotation value should be set in accordance to the corresponding axis value - in this case it has to be of DateTime type.
Please give it a try and if you still experience any issues, send us more concrete information on the scenario you have.
Thanks for your reply.
I know that the annotation value must be of type date in my case.
I define everything in xaml and uses binding to my view model.
I'll try again and let you know,
Can you provide an example using XAML and binding ?
To bind the value to the view model, you'll want to make sure the BindingContext is correct. By default, the BindingContext is the parent, which is the Chart itself. You'll instead want to set the source of the binding to the view model.
Let me show you via a demo.
I've attached a runnable demo for you, here's a short video of it in action at runtime. In the demo, I've bound the Annotation's Value to a property in the view model. You can then click a button several times to move that annotation around.
Let me take you through the highlights, the attached demo is fleshed out.
First, let's look at the view model. In it, there's a DateTime property in the view model named "AnnotationValue",
Now, let's look at the XAML. You're seeing the following:
- Set the axis
- Set the BindingContext source
- Binding the AnnotationValue property to Value
Run the demo and click the button a few times, you'll see the annotation move across horizontal axis tick locations (which correspond to the data point's DateTime value).
I hope this helps clarify what's going on and how you can get the result you're looking for.
Lance | Tech Support Engineer, Sr.