简体   繁体   中英

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

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...).

在此输入图像描述

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

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.

I wouldnt disable SmartLabelStyle but tune its parameters instead. You should look at the MovingDirection Property . This can control in what direction labels are allowed to move. So you might want to set its value to 'Top' Also to make it look more even you should specifiy Min and Max moving distance to the same ammount.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM