Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net charts - how to force data labels to display above a curve always?

Tags:

c#

.net

charts

On the blue curve in the below sample, the first data point (74.2%) displays below the curve, whereas the 3 other ones display above the curve (85.9%, 94.6%, 104.7%).

I initially thought labels would display below a point when that point would get too close from the top of the charting area. Actually, whether a label gets printed above or below a point seems to be fairly arbitrary (you will notice the first point is also the 'lowest' on the Y axis here...).

enter image description here

Is there a way to force labels to always print above their respective point ?

like image 712
BuZz Avatar asked Oct 24 '25 02:10

BuZz


1 Answers

You didn't post any repro code, hard to reverse-engineer the code from a screen-shot. Never skip this when you have a very specific problem like this.

Guessing at it, you are doing battle with the "Smart label" feature. Which somewhat inevitably means it will have a mind of its own that is sooner or later going to not do what you hope it does. You have some control over the way it is used through the Series.SmartLabelStyle property. First thing to definitely try is to set its Enabled property to false so it stops being smart. Next one you can tinker with is its AllowOutsidePlotArea property.

If none of this gets you anywhere then consider leveraging the Chart.PostPaint event and just draw these labels yourself. Giving you full control over where you put them of course.

like image 69
Hans Passant Avatar answered Oct 25 '25 16:10

Hans Passant