Canvas method must be used in the OnAfterDraw event?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
wwp3321
Newbie
Newbie
Posts: 60
Joined: Wed Jul 02, 2003 4:00 am

Post by wwp3321 » Thu Nov 20, 2008 10:51 am

It need not the file of "d:\\a.tee" .
You can save the "a.tee" by the button "Save Para".


if(FileExists("d:\\a.tee"))
{
LoadChartFromFile(Chart1,"d:\\a.tee");
}

wwp3321
Newbie
Newbie
Posts: 60
Joined: Wed Jul 02, 2003 4:00 am

Post by wwp3321 » Thu Nov 20, 2008 10:53 am

Maybe I forgeted to compile the source ,please recompile the source .

Thanks.

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

Post by Narcís » Thu Nov 20, 2008 11:15 am

Hi wwp3321,

Thanks for the information.

I could not get your project working. I guess it's something you set at designtime. However, setting up a new C++ Builder project, dropping a TChart and a TButton into a form, adding 2 series at designtime and using code below, produces a chart very similar to yours and works fine for me here.

Could you please check if this works fine at your end?

Code: Select all

//---------------------------------------------------------------------------
void __fastcall TForm3::FormCreate(TObject *Sender)
{
	Chart1->BottomAxis->SetMinMax(1,100);
	Chart1->LeftAxis->SetMinMax(1,100);

	Chart1->BottomAxis->Logarithmic=true;
	Chart1->LeftAxis->Logarithmic=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm3::Button1Click(TObject *Sender)
{
	int X0 = Chart1->BottomAxis->CalcXPosValue(10);
	int Y0 = Chart1->LeftAxis->CalcYPosValue(50);

	for (int i = 0; i < 5; i++)
	{
	  Chart1->Canvas->TextOut(X0,Y0,"OK");
	  X0++;
	  Y0++;
	}
}
//---------------------------------------------------------------------------
Thanks in advance
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

wwp3321
Newbie
Newbie
Posts: 60
Joined: Wed Jul 02, 2003 4:00 am

Post by wwp3321 » Thu Nov 20, 2008 11:21 am

It also didnt work with your codes.
With

Code: Select all

    int X0 = Chart1->Axes->Bottom->CalcXPosValue(10);
    int Y0 = Chart1->Axes->Left->CalcYPosValue(50);

    Chart1->Canvas->TextOutA(X0,Y0,"OK");
I can get one "OK";

With

Code: Select all

    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 ++;
        Y0 ++;
    }
I get nothing ,even one "OK";

wwp3321
Newbie
Newbie
Posts: 60
Joined: Wed Jul 02, 2003 4:00 am

Post by wwp3321 » Thu Nov 20, 2008 11:23 am

I paint all the source here.

Unit.h

Code: Select all

//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "ImaPoint.hpp"
#include <Chart.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <Series.hpp>
#include <TeEngine.hpp>
#include <TeeProcs.hpp>
#include "TeeTools.hpp"
#include "TeeEdit.hpp"

//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
    TChart *Chart1;
    TButton *btnSavepara;
    TChartEditor *ChartEditor1;
    TButton *btnLoadPara;
    TButton *btnEditchart;
    TButton *btnAddPoint;
    TFastLineSeries *Series2;
    TFastLineSeries *Series1;
    void __fastcall btnSaveparaClick(TObject *Sender);
    void __fastcall btnEditchartClick(TObject *Sender);
    void __fastcall btnAddPointClick(TObject *Sender);
    void __fastcall btnLoadParaClick(TObject *Sender);
    void __fastcall Chart1AfterDraw(TObject *Sender);
private:	// User declarations
public:		// User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Unit.cpp

Code: Select all

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "TeeStore.hpp"
#include "EditChar.hpp"
#include "TeeEditPRO.hpp"
#pragma link "TeeEditPRO"


//---------------------------------------------------------------------------
#pragma package(smart_init)

#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
   Chart1->BottomAxis->SetMinMax(1,100); 
   Chart1->LeftAxis->SetMinMax(1,100); 

   Chart1->BottomAxis->Logarithmic=true;
   Chart1->LeftAxis->Logarithmic=true;
}

//Load Tchart Parameters
void __fastcall TForm1::btnSaveparaClick(TObject *Sender)
{

   SaveChartToFile(Chart1,"d:\\a.tee",false,false);
}

//Edit chart
void __fastcall TForm1::btnEditchartClick(TObject *Sender)
{
    EditChart(Form1,Chart1);
}

//Add sample points
void __fastcall TForm1::btnAddPointClick(TObject *Sender)
{
    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 ++;
        Y0 ++;
    }
}

//Load chart Parameters
void __fastcall TForm1::btnLoadParaClick(TObject *Sender)
{
    if(FileExists("d:\\a.tee"))
    {
        LoadChartFromFile(Chart1,"d:\\a.tee");
    }
}

wwp3321
Newbie
Newbie
Posts: 60
Joined: Wed Jul 02, 2003 4:00 am

Post by wwp3321 » Thu Nov 20, 2008 11:28 am

I am very sorry .

Code: Select all

for(int i=0;i++;i<5) 
should be

Code: Select all

for(int i=0;i<5;i++) 
Best Regards
wwp


Now it work well ,but when I resized the form ,I have to Canvas again.
Is there any other way without painting again?

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

Post by Narcís » Thu Nov 20, 2008 11:32 am

Hi wwp3321,

As I previously told you, please try enable a flag in btnAddPointClick which it's checked in OnAfterDraw event and do the custom drawing there.

Thanks in advance.
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

wwp3321
Newbie
Newbie
Posts: 60
Joined: Wed Jul 02, 2003 4:00 am

Post by wwp3321 » Thu Nov 20, 2008 11:39 am

I think we have crossed posts.
Thanks very much!

Post Reply