Jump to content
Software FX Community

How to create annotation adjusted to scale of specific axis


Recommended Posts


I try to create annotation programmaticly (in my case this is rectange) that adjusted to scale of specific axis.

For example:

 I have axis Y that its range is 34-36 and axis X that it range 0-60 minutes (in ticks) .I need to create rectangle with the next coordinates

{(5,34.5),(5,35.5),(30,35.5),(30,34.5) }. When I use annotations I can to attach the annotation to specific point but when I create a rectangle I need to convert the values to pixels and I don't know how to do it (when I use Axis ValueToPixel function I get wrong coordinates and my rectangle gets wrong location and size) 

Link to comment
Share on other sites

Thanks to your response!

I reviewed my code and I think I understood the problem.When I draw the polygon there is no need to use the ValueToPixel method .It is enough to create the polygon and to use AttachHeight and AttachWidth methods .It works fine but only for non logarithmic axes.In case I use logarithmic one I have a problem.In my code I want to set annotation for example triangle with coordinates (2,10) (4,10) (4,100)  (see the code below).I create the triangle and use AtthachHeight(pol,2) AttachWidth(pol ,90). Triangle is streched as I wanted.Everything is allright.

Now I set the chart.AxisX.LogBase = 10.0 and I get trianle with width more than 90.

There are two scenarios:

1.I don't use the AtthachHeight and AttachWidth properly - so If it is the case please explain me how to do it .

2.This is the bug.

 Actually after some research I discoverd if I set AttachWidth (pol,100/10) instead of AttachWidth (pol,100-10) I get the desirable result.Frankly speaking from point of view of simple user it is a little buggy becouse I don't think I have to ajust my own data according to LogBase of Axis 


this is the code :



Window x:Class="CustomSteps.MainWindow"



Title="MainWindow" Height="350" Width="525" xmlns:cfx="http://schemas.softwarefx.com/chartfx/wpf/80">


<cfx:Chart Name="chart" /></Grid>



Code behind:

namespace CustomSteps


/// <summary>

/// Interaction logic for MainWindow.xaml

/// </summary>

public partial class MainWindow : Window


private Annotations _annotations;public MainWindow()





public struct MyPoint


public double X




public double Y




public DateTime Time





private void ReloadData()


MyPoint[] data1 = new MyPoint[21];


FillData(data1, 1);


SeriesAttributes sa1 = new SeriesAttributes();

sa1.ItemsSource = data1;


Pane pane = new Pane();Axis ax1 = new Axis();

ax1.Min = 0;

ax1.Max = 10;



sa1.AxisY = ax1;

sa1.AxisX = chart.AxisX;

sa1.BindingPathX = "X";sa1.BindingPath = "Y";


sa1.Gallery =

Gallery.Curve;chart.AxisX.DataPath = "X";chart.AxisX = new Axis();

chart.AxisX.LogBase = 10;

chart.AxisX.GetLabel += new AxisLabelEventHandler(AxisX_GetLabel);

chart.PanesPanel =

new StackPanePanel();







private void AddAnnotations(SeriesAttributes Ser)


Polygon pol = new Polygon();

pol.Stretch =


pol.Fill =

Brushes.Red;pol.Stroke = Brushes.Red;

pol.StrokeThickness = 2;

pol.Opacity = 0.5;

Point p1 = new Point(0, 0);

Point p2 = new Point(0, 1);Point p3 = new Point(1, 1);


pol.Points = new PointCollection() { p1, p2, p3};

if (_annotations == null)


_annotations = new Annotations();this.chart.Extensions.Add(_annotations);



Annotations.SetAxisY(pol, Ser.AxisY);

Annotations.SetAxisX(pol, this.chart.AxisX);Annotations.SetAttachX(pol, 10);

Annotations.SetAttachY(pol, 4);Annotations.SetAttachHeight(pol, 2);

//without log 10 - looks like right

//with log 10 looks wrongAnnotations.SetAttachWidth(pol, 100);Annotations.SetSeries(pol, Ser);


void AxisX_GetLabel(object sender, AxisLabelEventArgs e)




private void FillData(MyPoint[] data1, double factor)


for (int i = 0; i < data1.Length; i++)



data1.Y = i;

data1.X = i*10;






Link to comment
Share on other sites

Hello AndreG! (Sorry .I don't know your name)

May be I didn't explain myself clearly,but this is the point.I set SetAttachWidht to 100 units of axis x  and I expect that my triangle will be bounded between 10 to 110 units on axis x.But instead of this I get triangle that bounded between 10 and 1000 units and I suppose that this is uncorrect.I hope you understand me.


Link to comment
Share on other sites

Hello Alexey,

My name is Andre :)

SetAttachWidht sets the width using the X axis. Since the axis is in log, it uses log. 1 would be at the base of the triangle (regardless of the fact it is positioned at 10). If you want your triangle to be from 10 to 110, use the code below.

Annotations.SetAttachWidth(pol, 10);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...