Page 1 of 1

TCursorTool Bug?

Posted: Fri Nov 21, 2008 5:25 am
by 8574101
Hello,
I add a CursorTool at XValue that was entered at Edit1,
But there are two CursorTool being painted and at the wrong position.
Please take a look at the picture below.


[Img]
http://img1.freep.cn/p.aspx?u=v20_img1_ ... 103843.jpg
[/Img]

I have upload the source and application.

BTW: BCB6.0,Teechart6.01


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;
    TFastLineSeries *Series1;
    TFastLineSeries *Series2;
    TEdit *Edit1;
    TLabel *Label1;

    void __fastcall Chart1AfterDraw(TObject *Sender);
    void __fastcall Edit1KeyUp(TObject *Sender, WORD &Key,
          TShiftState Shift);
private:	// User declarations
    bool bDrawText;
public:		// User declarations
    __fastcall TForm1(TComponent* Owner);
    TCursorTool *curLine;
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Unit.cpp

Code: Select all

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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"


//---------------------------------------------------------------------------
#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->Axes->Bottom->Grid->Visible = false;
   Chart1->Axes->Left->Grid->Visible = false;
}


void __fastcall TForm1::Chart1AfterDraw(TObject *Sender)
{
   if(bDrawText)
   {
        int X0 = Chart1->Axes->Bottom->CalcXPosValue( StrToFloat(Edit1->Text) );
        int Y0 = Chart1->Axes->Left->CalcYPosValue(50);


        curLine = new TCursorTool(Series1);
        curLine->Pen->Style = psDot;
        curLine->Pen->Color = clGreen;
        curLine->ParentChart = Chart1;
        curLine->Series = Series1;
        curLine->Style = cssVertical;
        curLine->XValue = X0;
        Chart1->Canvas->TextOutA(X0,Y0,"Test");

   }
}


void __fastcall TForm1::Edit1KeyUp(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    if(Key == 13)
    {
        bDrawText = true;
        Chart1->Draw();
        bDrawText = false;
    }
}

[/img]

Posted: Fri Nov 21, 2008 10:12 am
by narcis
Hi wwp3321,

Code: Select all

		curLine->Style = cssVertical;
This works fine for me here using TeeChart Pro v8.04 VCL.

For the cursor to refresh you may need to implement Edit1KeyUp like this:

Code: Select all

void __fastcall TForm1::Edit1KeyUp(TObject *Sender, WORD &Key,
	  TShiftState Shift)
{
	if(Key == 13)
	{
		bDrawText = true;
		Chart1->Draw();
		bDrawText = false;
		Chart1->Draw();
	}
}
Cursor was not placed in the correct position because you where using pixel screen cordinates instead of axes values, you need to set cursor like this:

Code: Select all

void __fastcall TForm1::Chart1AfterDraw(TObject *Sender)
{
   if(bDrawText)
   {
		float XVal = StrToFloat(Edit1->Text);

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

		curLine = new TCursorTool(Series1);
		curLine->Pen->Style = psDot;
		curLine->Pen->Color = clGreen;
		curLine->ParentChart = Chart1;
		curLine->Series = Series1;
		curLine->Style = cssVertical;
		curLine->XValue = XVal;
		curLine->XValue = XVal;
		Chart1->Canvas->TextOutA(X0,Y0,"Test");
   }
}
Notice that curLine->XValue needs to be assigned twice. First time its value is not updated. This is a known issue for which we haven't found a solution so far.