Page 1 of 1
Graphics Object in T-Chart
Posted: Wed May 13, 2009 11:13 am
by 9641422
Hi,
There is a problem I’m facing related to the graphics object of T-Chart. Whenever I try to create a box on T-Chart on the click of button using the graphics object, generally it throws an exception that “Parameter is not valid” on the following line of code
gr.DrawPolygon(pen, pointArray);
But sometimes it creates the box too out of the same code. Please let me know if I’m making any mistake or there is some better way to do graphics drawing on T-Chart, like drawing polygon and drawing lines, etc.
Below is the code I’m using to draw the box.
private void button1_Click(object sender, EventArgs e)
{
Steema.TeeChart.Drawing.Graphics3D gr = tChart1.Graphics3D;
tChart1.Aspect.View3D = false;
Pen pen = new Pen(Color.Black);
pen.Width = 2;
Rectangle rect = new Rectangle();
rect = tChart1.Chart.ChartRect;
float fXMargin = rect.X;
float fYmargin = rect.Y;
PointF[] pointArray = new PointF[4];
try
{
pointArray[0].X = fXMargin + 30;
pointArray[0].Y = fYmargin + 10;
pointArray[1].X = fXMargin + 150;
pointArray[1].Y = fYmargin + 10;
pointArray[2].X = 150 + fXMargin;
pointArray[2].Y = rect.Height - 10 + fYmargin;
pointArray[3].X = fXMargin + 30;
pointArray[3].Y = rect.Height - 10 + fYmargin;
gr.DrawPolygon(pen, pointArray);
}
catch { }
}
Thanks.
Posted: Wed May 13, 2009 2:41 pm
by narcis
Hi Amol,
Code below works fine for me here using latest TeeChart for .NET v3 release available.
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private bool go = false;
private void InitializeChart()
{
Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.FillSampleValues();
tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
}
void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
if (go)
{
Steema.TeeChart.Drawing.ChartPen pen = new Steema.TeeChart.Drawing.ChartPen(Color.Black);
pen.Width = 2;
Rectangle rect = tChart1.Chart.ChartRect;
int fXMargin = rect.Left;
int fYmargin = rect.Top;
Point[] pointArray = new Point[5];
try
{
pointArray[0].X = fXMargin + 30;
pointArray[0].Y = fYmargin + 10;
pointArray[1].X = fXMargin + 150;
pointArray[1].Y = fYmargin + 10;
pointArray[2].X = 150 + fXMargin;
pointArray[2].Y = rect.Height - 10 + fYmargin;
pointArray[3].X = fXMargin + 30;
pointArray[3].Y = rect.Height - 10 + fYmargin;
pointArray[4] = pointArray[0];
Steema.TeeChart.Drawing.Graphics3D gr = tChart1.Graphics3D;
gr.Pen = pen;
gr.Polygon(pointArray);
}
catch { }
}
}
private void button1_Click(object sender, EventArgs e)
{
tChart1.Aspect.View3D = false;
go = true;
}
Using v2 you can do this:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private bool go = false;
private void InitializeChart()
{
Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.FillSampleValues();
tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
}
void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
if (go)
{
Pen pen = new Pen(Color.Black);
pen.Width = 2;
Rectangle rect = new Rectangle();
rect = tChart1.Chart.ChartRect;
float fXMargin = rect.X;
float fYmargin = rect.Y;
PointF[] pointArray = new PointF[4];
try
{
pointArray[0].X = fXMargin + 30;
pointArray[0].Y = fYmargin + 10;
pointArray[1].X = fXMargin + 150;
pointArray[1].Y = fYmargin + 10;
pointArray[2].X = 150 + fXMargin;
pointArray[2].Y = rect.Height - 10 + fYmargin;
pointArray[3].X = fXMargin + 30;
pointArray[3].Y = rect.Height - 10 + fYmargin;
Steema.TeeChart.Drawing.Graphics3D gr = tChart1.Graphics3D;
gr.DrawPolygon(pen, pointArray);
}
catch { }
}
}
private void button1_Click(object sender, EventArgs e)
{
tChart1.Aspect.View3D = false;
go = true;
}
Posted: Sat May 16, 2009 7:31 am
by 9641422
Hi,
Thanks for the feedback that you have sent. But we don’t want the box to be created at Tchart_AfterDraw event. Actually we are creating manual grid lines and curves in the box. If we create box and manual grid lines in Tchart_AfterDraw event and draw curves on button click event then finally we will get the manual grid lines drawn above the curves. Hence we wanted to create box and manual grid lines on button click before the curves are drawn, so that curves are on top of manual grid lines every time. Please tell if box and manual grid lines can be done on button click event only, as graphics object in that case is throwing an exception.
If it is not possible and drawing the box and manual grid lines can be done on Tchart_AfterDraw event only, and then is there any way that manual grid lines can be set at the back of the curves, so that we get the curves on the top view.
Please revert back asap.
Thanks
Posted: Mon May 18, 2009 10:18 am
by 10050769
Hello Amol,
I suggest next code solution for your application using
BeforeDrawSeries Event , that draw series above box.
Using version 3:
Code: Select all
private void InitializeChart()
{
Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.FillSampleValues();
tChart1.BeforeDrawSeries += new Steema.TeeChart.PaintChartEventHandler(tChart1_BeforeDrawSeries);
}
void tChart1_BeforeDrawSeries(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
if (go)
{
Steema.TeeChart.Drawing.ChartPen pen = new Steema.TeeChart.Drawing.ChartPen(Color.Black);
pen.Width = 2;
Rectangle rect = tChart1.Chart.ChartRect;
int fXMargin = rect.Left;
int fYmargin = rect.Top;
Point[] pointArray = new Point[5];
try
{
pointArray[0].X = fXMargin + 30;
pointArray[0].Y = fYmargin + 10;
pointArray[1].X = fXMargin + 150;
pointArray[1].Y = fYmargin + 10;
pointArray[2].X = 150 + fXMargin;
pointArray[2].Y = rect.Height - 10 + fYmargin;
pointArray[3].X = fXMargin + 30;
pointArray[3].Y = rect.Height - 10 + fYmargin;
pointArray[4] = pointArray[0];
Steema.TeeChart.Drawing.Graphics3D gr = tChart1.Graphics3D;
gr.Pen = pen;
gr.Polygon(pointArray);
}
catch { }
}
}
Using version 2:
Code: Select all
private void InitializeChart()
{
Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.FillSampleValues();
tChart1.BeforeDrawSeries += new Steema.TeeChart.PaintChartEventHandler(tChart1_BeforeDrawSeries);
}
void tChart1_BeforeDrawSeries(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
if (go)
{
Pen pen = new Pen(Color.Black);
pen.Width = 2;
Rectangle rect = new Rectangle();
rect = tChart1.Chart.ChartRect;
float fXMargin = rect.X;
float fYmargin = rect.Y;
PointF[] pointArray = new PointF[4];
try
{
pointArray[0].X = fXMargin + 30;
pointArray[0].Y = fYmargin + 10;
pointArray[1].X = fXMargin + 150;
pointArray[1].Y = fYmargin + 10;
pointArray[2].X = 150 + fXMargin;
pointArray[2].Y = rect.Height - 10 + fYmargin;
pointArray[3].X = fXMargin + 30;
pointArray[3].Y = rect.Height - 10 + fYmargin;
Steema.TeeChart.Drawing.Graphics3D gr = tChart1.Graphics3D;
gr.DrawPolygon(pen, pointArray);
}
catch { }
}
}
I hope that will helps,
Thanks,