Strange behaviour when manually positioning Annotations.
Posted: 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();
}
}
}
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();
}
}
}