TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
-
wwp3321
- Newbie
- Posts: 60
- Joined: Wed Jul 02, 2003 4:00 am
Post
by wwp3321 » Wed Nov 19, 2008 8:51 am
Hello,
Canvas method must be used in the OnAfterDraw event?
The following codes didn't work well.Nothing was painted on the Chart1.
Code: Select all
void __fastcall TForm1::Button4Click(TObject *Sender)
{
int X0 = Chart1->Axes->Bottom->CalcXPosValue(10);
int Y0 = Chart1->Axes->Left->CalcYPosValue(50);
for(int i=0;i++;i<5)
{
Chart1->Canvas->TextOutA(X0,Y0,"OK");
X0 += 20;
Y0 += 20;
}
}
Best Regards
wwp3321
-
wwp3321
- Newbie
- Posts: 60
- Joined: Wed Jul 02, 2003 4:00 am
Post
by wwp3321 » Wed Nov 19, 2008 9:01 am
The following codes also don't work very well, sometimes the "OK" text just flashed on the Chart1 and disappeared; sometimes the "OK" text can be well painted ,but It disappeared when I Minimize the Form .
Code: Select all
void __fastcall TForm1::Button4Click(TObject *Sender)
{
int X0 = Chart1->Axes->Bottom->CalcXPosValue(10);
int Y0 = Chart1->Axes->Left->CalcYPosValue(50);
Chart1->Canvas->TextOutA(X0,Y0,"OK");
}
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Wed Nov 19, 2008 9:07 am
Hi wwp3321,
Yes, you need to use this in the OnAfterDraw event because calls like
Chart1->Axes->Bottom->CalcXPosValue(10) need the chart being painted before so they can be correctly calculated and provide valid values. A simple example using a pie series:
Code: Select all
procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
Chart1.Title.Text.Add(IntToStr(Series1.XRadius));
Chart1.Title.Text.Add(IntToStr(Series1.YRadius));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.FillSampleValues();
Chart1.Draw;
end;
Hope this helps!
-
wwp3321
- Newbie
- Posts: 60
- Joined: Wed Jul 02, 2003 4:00 am
Post
by wwp3321 » Thu Nov 20, 2008 1:31 am
Now customers want to add the mark by themself.
For example,they want to add a mark at some position by pushing
the Button1.But the following codes don't work well.
Code: Select all
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int X0 = Chart1->Axes->Bottom->CalcXPosValue(10);
int Y0 = Chart1->Axes->Left->CalcYPosValue(50);
Chart1->Canvas->TextOutA(X0,Y0,"OK");
}
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Thu Nov 20, 2008 8:12 am
Hi wwp3321,
This works fine for me here using code below TeeChart Pro v8.04 VCL. Which TeeChart version are you using?
Code: Select all
//---------------------------------------------------------------------------
void __fastcall TForm3::Button1Click(TObject *Sender)
{
int X0 = Chart1->Axes->Bottom->CalcXPosValue(10);
int Y0 = Chart1->Axes->Left->CalcYPosValue(50);
Chart1->Canvas->TextOutA(X0,Y0,"OK");
}
//---------------------------------------------------------------------------
void __fastcall TForm3::FormCreate(TObject *Sender)
{
Series1->Clear();
for (int i=0; i < 100; i++) {
Series1->Add(i);
}
}
//---------------------------------------------------------------------------
You may also want to try calling Draw method before retrieving axes positions, for example:
Code: Select all
void __fastcall TForm3::Button1Click(TObject *Sender)
{
Chart1->Draw();
int X0 = Chart1->Axes->Bottom->CalcXPosValue(10);
int Y0 = Chart1->Axes->Left->CalcYPosValue(50);
Chart1->Canvas->TextOutA(X0,Y0,"OK");
}
Thanks in advance.
-
wwp3321
- Newbie
- Posts: 60
- Joined: Wed Jul 02, 2003 4:00 am
Post
by wwp3321 » Thu Nov 20, 2008 9:06 am
My TeeChart version is 6.01
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Thu Nov 20, 2008 9:08 am
Hi wwp3321,
Could you please try calling Draw method as I suggested?
Thanks in advance.
-
wwp3321
- Newbie
- Posts: 60
- Joined: Wed Jul 02, 2003 4:00 am
Post
by wwp3321 » Thu Nov 20, 2008 9:54 am
Code: Select all
void __fastcall TForm3::Button1Click(TObject *Sender)
{
Chart1->Draw();
int X0 = Chart1->Axes->Bottom->CalcXPosValue(10);
int Y0 = Chart1->Axes->Left->CalcYPosValue(50);
Chart1->Canvas->TextOutA(X0,Y0,"OK");
}
When I Minimize the form ,"OK" disappeared.
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Thu Nov 20, 2008 9:59 am
Hi wwp3321,
Yes, because the chart has been repainted and custom text has not been painted this time. You'd better use this code in the OnAfterDraw event with a flag being enabled in the button clicked event, something like this:
Code: Select all
//---------------------------------------------------------------------------
void __fastcall TForm3::Button1Click(TObject *Sender)
{
DrawText=true;
Chart1->Draw();
}
//---------------------------------------------------------------------------
void __fastcall TForm3::Chart1AfterDraw(TObject *Sender)
{
if (DrawText) {
int X0 = Chart1->Axes->Bottom->CalcXPosValue(10);
int Y0 = Chart1->Axes->Left->CalcYPosValue(50);
Chart1->Canvas->TextOutA(X0,Y0,"OK");
}
}
//---------------------------------------------------------------------------
-
wwp3321
- Newbie
- Posts: 60
- Joined: Wed Jul 02, 2003 4:00 am
Post
by wwp3321 » Thu Nov 20, 2008 10:00 am
Code: Select all
Chart1->Draw();
int X0 = Chart1->Axes->Bottom->CalcXPosValue(10);
int Y0 = Chart1->Axes->Left->CalcYPosValue(50);
for(int i=0;i++;i<5)
{
Chart1->Canvas->TextOutA(X0,Y0,"OK");
X0 += 20;
Y0 += 20;
}
The codes above painted nothting,even one "OK".
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Thu Nov 20, 2008 10:07 am
Hi wwp3321,
We may have crossed posts. Could you please check my last reply?
Thanks in advance.
-
wwp3321
- Newbie
- Posts: 60
- Joined: Wed Jul 02, 2003 4:00 am
Post
by wwp3321 » Thu Nov 20, 2008 10:14 am
8574101 wrote:Code: Select all
Chart1->Draw();
int X0 = Chart1->Axes->Bottom->CalcXPosValue(10);
int Y0 = Chart1->Axes->Left->CalcYPosValue(50);
for(int i=0;i++;i<5)
{
Chart1->Canvas->TextOutA(X0,Y0,"OK");
X0 += 20;
Y0 += 20;
}
Please check the codes above.
The codes above painted nothting,even one "OK".
The codes above should paint five "OK".
BTW: I didn't resize the form.
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Thu Nov 20, 2008 10:18 am
Hi wwp3321,
Please 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.
Thanks in advance.
-
wwp3321
- Newbie
- Posts: 60
- Joined: Wed Jul 02, 2003 4:00 am
Post
by wwp3321 » Thu Nov 20, 2008 10:34 am
I have upload the source.
BCB6.0,Teechart6.01
Received TestTchartCanvas.zip Content Type application/x-zip-compressed Length 1903376
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Thu Nov 20, 2008 10:42 am
Hi wwp3321,
Thanks for the example project but I'm not able to run it because a.tee is not included. Could you please send the tee file too?
Thanks in advance.