Annotation does not display on asp.net chart control

rckrch
rckrch used Ask the Experts™
on
I have a chart control in asp.net that I am trying to display annotation in the chart area - topcenter of 'ChartArea1'.  It does not display on the chart.

Why?

Below is my asp.net code

<Annotations>
                                        
<asp:TextAnnotation Alignment="TopCenter" Font="Arial, 10pt" ForeColor="#00FFCC"
Name="Chart1Annotation" Text="Nominal" TextStyle="Default" ClipToChartArea="ChartArea1">
</asp:TextAnnotation>
</Annotations>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Not much to go on - can you give us a link to the code or if unable post your rendered HTML.

Commented:
You don't show the code where you've attached the annotation to the chart itself. I see the "ClipToChartArea" but that's not enough to associate the annotation with the chart.

Your Chart object should have an Annotations collection - the code you showed looks like it might be that annotations collection, but there's not enough to see that for sure.

Author

Commented:
Thanks for the response!

This is the code behind as well.  The ASP.Net code I sent earlier and this code behind are what I have for this annotation.

Thanks,

Chart1.Annotations.Clear()
        Dim Chart1Annot As New DataVisualization.Charting.TextAnnotation 
        Chart1.Annotations.Add(Chart1Annot)
        Chart1Annot.ForeColor = Color.Coral
        Chart1Annot.Font = New Font("Arial", 10)
        Chart1.Annotations.
        'Chart1Annot = Chart1.Annotations.FindByName("Chart1Annotation")
        Chart1Annot.Text = "Nom: " & Nominal11.Text & " High: " & High11.Text & " Low: " & Low11.Text
        Chart1Annot.BringToFront()

Open in new window

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
On line 6, you seem to have some broken code:
Chart1.Annotations.

Open in new window

Author

Commented:
Thanks gr8gonzo,

I took that line out and I still have no annotation on the chart.

Commented:
I'm a little curious how that line didn't throw an exception. If you are looking at this code in visual studio, then VS should tell you about it. I would suggest putting that line back in temporarily, and then checking it with visual studio to make sure it is showing up as an error. If it isn't, then something is wrong with your VS setup. If that's the case, then there might be other errors that might be leading to the annotation code not being executed correctly.

Author

Commented:
I had been trying different lines to resolve the issue and this was part of a line that was edited before I loaded on Experts exchange.  It did show an error after I had edited it and inadvertently didn't delete the line.  It was not intended to be part of the code the way it was written.  the intelisense did detect the incomplete code.  

Should this code work as written - if it should it is still not working.  Should this be part of the triggers in the update panel?

Thanks,
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Hi rckrch,

You are missing Anchoring details. As far as I recollect, Annotations must be anchored. You can use the AnchorDataPoint property, or can set AnchorX and AnchorY properties.

Regards,
Chinmay.

Author

Commented:
Thanks Chinmay Patel,

I tried several values for anchorX and anchorY such as 5 and 20 but nothng happens.
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Hi rckrch,

Can you try setting them both to "NaN" please.

Regards,
Chinmay.

Author

Commented:
Thanks Chinmay,

I tried this and nothing happened.  I set both at NaN.
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Fair enough. Let me give it a shot today and see if I find something. It's been a while since I tried it.

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial