Strange behaviour when manually positioning Annotations.

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
gamed
Newbie
Newbie
Posts: 12
Joined: Fri Oct 21, 2005 4:00 am

Strange behaviour when manually positioning Annotations.

Post by gamed » Mon Mar 23, 2009 9:01 am

Dear Team,

please assume a Form with a TeeChart (tChart1) on it and a Button (button1) for the following code to be working. Please check that after starting up the Form the annotation is not at the correct position (it should be where the band is) also afetr pressing the button the position is not correct and the size differs every time we press the button.
What am i missing here?

TeeChart 2.0.2511.18118 , VS 2008

Thanks in advance.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
DrawChart();
}

private void DrawChart()
{
//General settings for the chart
tChart1.Chart.Aspect.View3D = false;
tChart1.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;
tChart1.BackColor = Color.White;

//Create some dummy data
DataTable dt = new DataTable();
dt.Columns.Add("x", typeof(DateTime));
dt.Columns.Add("y", typeof(Decimal));

dt.Rows.Add(new DateTime(2009, 3, 23, 8, 45, 0), 200);
dt.Rows.Add(new DateTime(2009, 3, 23, 9, 00, 0), 250);
dt.Rows.Add(new DateTime(2009, 3, 23, 9, 15, 0), 230);
dt.Rows.Add(new DateTime(2009, 3, 23, 9, 30, 0), 270);


//Create a new series for the data
Steema.TeeChart.Styles.Line line = new Steema.TeeChart.Styles.Line(tChart1.Chart);

line.XValues.DateTime = true;
line.DataSource = dt;
line.XValues.DataMember = "x";
line.YValues.DataMember = "y";


//Now set the x-axis to trunc to full hours
DateTime start = new DateTime(2009, 3, 23, 8, 00, 0), end = new DateTime(2009, 3, 23, 10, 00, 0);

tChart1.Axes.Bottom.SetMinMax(start, end);

//Now add a color band to highlight some range
Steema.TeeChart.Tools.ColorBand band = new Steema.TeeChart.Tools.ColorBand(tChart1.Chart);
band.Axis = tChart1.Axes.Bottom;

band.Color = Color.Blue;
band.Transparency = 50;
band.Start = new DateTime(2009, 3, 23, 8, 45, 0).ToOADate();
band.End = new DateTime(2009, 3, 23, 9, 30, 0).ToOADate();

//Now add an annotation for the range
Steema.TeeChart.Tools.Annotation a = new Steema.TeeChart.Tools.Annotation();
a.Text = String.Format("{0}\n{1}", "Line1", "Line2");
a.TextAlign = StringAlignment.Center;
a.Shape.Color = Color.Silver;
a.Shape.Transparency = 80;
tChart1.Tools.Add(a);

a.CustomSize = true;
a.Shape.Shadow.Visible = false;
a.Shape.CustomPosition = true;

a.Shape.Left = tChart1.Axes.Bottom.CalcXPosValue(band.Start);
a.Shape.Width = tChart1.Axes.Bottom.CalcSizeValue(band.End - band.Start);
a.Shape.Top = 60;
a.Shape.Bottom = 100;
}

private void button1_Click(object sender, EventArgs e)
{
DrawChart();
}
}
}

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Mon Mar 23, 2009 11:57 am

Hi gamed,

You are positioning your Annotation taking positions relative to the chart but the chart isn't still drawn. So, to ensure that you are taking "actual" chart positions, call the following before setting your tool position:

Code: Select all

tChart1.Draw();
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

gamed
Newbie
Newbie
Posts: 12
Joined: Fri Oct 21, 2005 4:00 am

Sill no success

Post by gamed » Mon Mar 23, 2009 12:09 pm

I managed to call the Draw (tChart1.Draw(this.CreateGraphics()); - hope this is right) after the SetMinMax() of the axis. Now the Annotation draws but it is still displaying incorrect (Right side is not corresponding to the Band). And additionally if you start minimizing and maximnizing the form to invoke a repaint of the chart, the annotation starts growing to the right.

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Mon Mar 23, 2009 12:44 pm

Hi gamed,

To have an annotation as large as your ColorBand, you could use this:

Code: Select all

a.Width = tChart1.Axes.Bottom.CalcSizeValue(band.End - band.Start) - 1;
gamed wrote:And additionally if you start minimizing and maximnizing the form to invoke a repaint of the chart, the annotation starts growing to the right.
I'm not sure to understand what problem are you suffering here. Are you changing anything at OnAfterDraw event? Could you please try to explain what are you exactly doing? Or could you send us a simple example project we can run "as-is" to reproduce the problem here?
You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

gamed
Newbie
Newbie
Posts: 12
Joined: Fri Oct 21, 2005 4:00 am

Post by gamed » Mon Mar 23, 2009 12:54 pm

followed up in newsgroup

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Mon Mar 23, 2009 3:16 pm

Hi gamed,

Excuse me, for v3 this is working fine. But for v2 there seem to be some problems drawing the annotation custom rectangle.

Also note that for v2 the "repaint" call we recommend is:

Code: Select all

Bitmap bmp = tChart1.Bitmap;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

gamed
Newbie
Newbie
Posts: 12
Joined: Fri Oct 21, 2005 4:00 am

Post by gamed » Tue Mar 24, 2009 7:20 am

Thank you for your reply, can i assume this problem is going to be fixed in version 2 or do i have to upgrade to version 3 to get around this.
Alos the refresh i added to repaint the chart was not an intentional refresh. it was just to show what happens when the chart is painting again (what i previously invoked with minimizing and maximizing the form to get winforms to repaint)

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Mar 24, 2009 11:39 am

Hi gamed,

I'm afraid it's unlickely this will be fixed in v2. v3 was released almost 2 years ago an v4 is already in its beta stage.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

gamed
Newbie
Newbie
Posts: 12
Joined: Fri Oct 21, 2005 4:00 am

Post by gamed » Tue Mar 24, 2009 11:49 am

Ok, so we need to upgrade anyways. Is there already a planned release date for v4?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Mar 24, 2009 12:08 pm

Hi gamed,

We expect it to be out very soon, probably at the beginning of April.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

gamed
Newbie
Newbie
Posts: 12
Joined: Fri Oct 21, 2005 4:00 am

Post by gamed » Tue Mar 24, 2009 12:15 pm

Good News - Thank you for your support

Post Reply