How do I get SizeScreenCoors when I set the Size of Annotation to Automatic?
Moderator: Queue Moderators
-
- Posts: 4
- Joined: Tue Dec 12, 2023 8:37 am
How do I get SizeScreenCoors when I set the Size of Annotation to Automatic?
Now SizeScreenCoords is always an incorrect value。
-
- Posts: 557
- Joined: Mon Mar 14, 2016 9:22 am
Re: How do I get SizeScreenCoors when I set the Size of Annotation to Automatic?
If you want to ask question, please provide enough information. It is not very useful to say "incorrect".
Please write down exactly how you are setting Annotation's properties and what result you want to get?
Please write down exactly how you are setting Annotation's properties and what result you want to get?
-
- Posts: 4
- Joined: Tue Dec 12, 2023 8:37 am
Re: How do I get SizeScreenCoors when I set the Size of Annotation to Automatic?
This is the code for setting annotations:
I need to obtain the width and height of the annotation,Here is the code for obtaining dimensions:
AnnotationWidth is always 100, and AnnotationHeight is always 50. It is obvious that these two values are incorrect because I roughly estimated them to be around 70 and 20 respectively, and the values obtained will not change when the text content changes.
Code: Select all
AnnotationXY annotation = new AnnotationXY(ChartView.ViewXY, ChartView.ViewXY.XAxes[1], ChartView.ViewXY.YAxes[1])
{
Style = AnnotationStyle.Rectangle,
LocationCoordinateSystem = CoordinateSystem.RelativeCoordinatesToTarget,
BorderVisible = false,
AllowDragging = false,
AllowResize = false,
AllowRotate = false,
AllowTargetMove = false,
AllowAnchorAdjust = false,
AllowUserInteraction = false,
Anchor = new PointDoubleXY(0, 1),
AutoSizePadding = 2,
ArrowStyleBegin = ArrowStyle.None,
ArrowStyleEnd = ArrowStyle.None,
Behind = true,
KeepVisible = false,
Visible = false,
Sizing = AnnotationXYSizing.Automatic
};
Code: Select all
AnnotationXY annotation = ChartView.ViewXY.Annotations[0];
var annotationWidth = annotation.SizeScreenCoords.Width;
var annotationHeight = annotation.SizeScreenCoords.Height;
-
- Posts: 557
- Joined: Mon Mar 14, 2016 9:22 am
Re: How do I get SizeScreenCoors when I set the Size of Annotation to Automatic?
You can not read annotation.SizeScreenCoords property, if you not set it. That is, this property is used only with Sizing = AnnotationXYSizing.ScreenCoordinates. This property does not report rendering size, if your AnnotationXYSizing is 'Automatic' or 'AxisValuesBoundaries'.
If you want 'Automatic' size approximation, then you should measure text (based on Font and string). Below is the code for such estimate:
Note that chart should rendered (on the screen) before you can use MeasureTextPX() method.
If you want 'Automatic' size approximation, then you should measure text (based on Font and string). Below is the code for such estimate:
Code: Select all
float fMaxWidth = 0;
float fMaxHeight = 0;
string[] aContent = annotation.Text.Split('\n');
for (int i = 0; i < aContent.Length; i++)
{
var point = _chart.MeasureTextPX(aContent[i], annotation.TextStyle.Font);
if (fMaxWidth < point.X)
fMaxWidth = point.X;
fMaxHeight += point.Y;
}
size = new Size(fMaxWidth + 2 * annotation.AutoSizePadding, fMaxHeight + 35);
-
- Posts: 4
- Joined: Tue Dec 12, 2023 8:37 am
Re: How do I get SizeScreenCoors when I set the Size of Annotation to Automatic?
Okay, thank you very much