in

Software FX Community

Discuss and find help for all Software FX products.

Problems using Annotations in the code behind

Last post 06-11-2009 4:52 PM by JuanC. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 06-11-2009 3:43 PM

    Problems using Annotations in the code behind

    I'm trying to figure out how to use the Annotations extension in the code behind for WPF.

    My scenario is that my user would right click on a chart to access a Context Menu option to "Add an Annotation" and I would respond to the event and add a new annotation at the users mouse location. I have been reviewing other forum posts and API Reference documentation from the Software FX Resource Center, but up to this point I can only get Annotations to work by directly putting them in the XAML - and then only if I use the Canvas properties to set the location. Setting the AttachX and AttachY in XAML does not work either. (At least from my experience).

    I am using the ChartFx for WPF Trial Download for my testing.

    Here is what I have put together in the code behind, but doesn't work...

    
    Annotations annots = new Annotations();
    chart1.Extensions.Add(annots);
    
    Rectangle rectangle = new Rectangle();
    rectangle.Fill = Brushes.Red;
    rectangle.Stroke = Brushes.Black;
    
    Annotations.SetAttachX(rectangle, 2);
    Annotations.SetAttachY(rectangle, 5);
    Annotations.SetAttachHeight(rectangle, 2);
    Annotations.SetAttachWidth(rectangle, 4);
    
    annots.Children.Add(rectangle);
    
    

    I am using the sample application (PassingData) as my test project. I updated the CLRObjectPage page with these changes in the code behind. No luck.

    Any ideas?

    Filed under: , ,
  • 06-11-2009 4:38 PM In reply to

    • juanZ
    • Top 10 Contributor
    • Joined on 02-04-2009

    Re: Problems using Annotations in the code behind

     Hi,

     

    Try to set the heigth and width property to the rectangle.

     

                Annotations annot = new Annotations();
                chart1.Extensions.Add(annot);

                Rectangle rectangle = new Rectangle();
                rectangle.Width = 20;
                rectangle.Height = 20;

                rectangle.Fill = new LinearGradientBrush(Color.FromRgb(0, 255, 0),Color.FromRgb(0, 255, 0),45.00);
                rectangle.Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0));

                Annotations.SetAttachX(rectangle, 2);
                Annotations.SetAttachY(rectangle, 40);
                annot.Children.Add(rectangle);

     

    This worked for me.

    Juan Zamora
    Software FX Support
    www.softwarefx.com
  • 06-11-2009 4:52 PM In reply to

    • JuanC
    • Top 10 Contributor
    • Joined on 03-02-2007

    Re: Problems using Annotations in the code behind

    I tested your code "as is" and it worked for me. Please note that if you use AttachWidth or AttachHeight, the dimensions of these properties are expressed in axis units, if your Y axis goes from 0 to 1 million and you use AttachHeight 2, we will ask the axis to translate 2 into pixels and that might result in a very very small rectangle.

    When I tested your code (using AttachWidth and AttachHeight) on a chart with 12 points and a Y axis from 0 to 100, I can see the red rectangle.

    Note that the same applies to AttachX and AttachY, they will be converted from axis units to pixels.

    Regards,

    JuanC

Page 1 of 1 (3 items)
Copyright 2008 Software FX, Inc.