1

While using a C++ builder 6 XE4 for creating a finance charts, i was trying to create, draw line feature. The Series that i had created was candle Stick Series. I tried to move to the XY co-ordinate as pointed out by the mouse pointer but whenever the below piece of code was hit, it threw an exception.

Chart1->Canvas->MoveTo(10,20); --> have given some valid values.

Is it possible to draw a line or any figures on the Chart (not on the form)? If yes, could you please let me know, how should it be done.

Thanks.

1 Answers1

0

Yes, TeeChart Pro VCL/FMX includes DrawLine tool (TDrawLineTool) for that purpose. With the TeeChart version shipped with C++ Builder XE4 you can manually draw the lines on the chart canvas doing something similar as in the code example below.

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

#include <vcl.h>
#pragma hdrstop

#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "VCLTee.CandleCh"
#pragma link "VCLTee.OHLChart"
#pragma resource "*.dfm"
TForm2 *Form2;
int X0,Y0;
int X1,Y1;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
    : TForm(Owner)
{
    X0=-1;
    Y0=-1;
    X1=-1;
    Y1=-1;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Chart1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
          int X, int Y)
{
    if ((X0==-1) || (Y0==-1)) {
        X0=X;
        Y0=Y;
    }
    else {
        X1=X;
        Y1=Y;
        Chart1->Draw();
    }

}
//---------------------------------------------------------------------------
void __fastcall TForm2::Chart1AfterDraw(TObject *Sender)
{
    if ((X1!=-1) && (Y1!=-1)) {
        Chart1->Canvas->Line(X0,Y0,X1,Y1);
        X0=-1;
        Y0=-1;
        X1=-1;
        Y1=-1;
    }
}
//---------------------------------------------------------------------------
Narcís Calvet
  • 7,304
  • 5
  • 27
  • 47