Page 1 of 1

Strange behaviour when manually positioning Annotations.

Posted: Mon Mar 23, 2009 9:01 am
by 9638875
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();
}
}
}

Posted: Mon Mar 23, 2009 11:57 am
by yeray
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();

Sill no success

Posted: Mon Mar 23, 2009 12:09 pm
by 9638875
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.

Posted: Mon Mar 23, 2009 12:44 pm
by yeray
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.

Posted: Mon Mar 23, 2009 12:54 pm
by 9638875
followed up in newsgroup

Posted: Mon Mar 23, 2009 3:16 pm
by yeray
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;

Posted: Tue Mar 24, 2009 7:20 am
by 9638875
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)

Posted: Tue Mar 24, 2009 11:39 am
by narcis
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.

Posted: Tue Mar 24, 2009 11:49 am
by 9638875
Ok, so we need to upgrade anyways. Is there already a planned release date for v4?

Posted: Tue Mar 24, 2009 12:08 pm
by narcis
Hi gamed,

We expect it to be out very soon, probably at the beginning of April.

Posted: Tue Mar 24, 2009 12:15 pm
by 9638875
Good News - Thank you for your support