I am using TeeCHart 7 with Turbo C++ Builder. I need to be able to place an annotation on the chart at a specific place using a click event. I was able to use "Annotation Tools" by clicking on the background, but the did not follow the chart series when zoomed. I thought about using Series Labels, but I am having problems getting the right C++ code to do that. I have used TC for a long time, but I have forgotten how to programatically write to the labels and can't seem to track it down. Pleas refresh my memort. Is there any other option to accomplish this task? I might have to use Seriws labels for time stamps so they might not be available for annotations. Can I make the "Tools" stick to the series?
thanks.
Chart Annotations
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Kev,
To achieve what you request you should set the annotations position relative to any chart element: series, axes, legend, etc. You should also call the positioning code at the OnZoom, OnUndoZoom and OnScroll events. At the forums threads below you'll find some examples on how to set custom positions:
http://www.teechart.net/support/viewtopic.php?t=4770
http://www.teechart.net/support/viewtopic.php?t=1758
If this doesn't help don't hesitate to let us know.
To achieve what you request you should set the annotations position relative to any chart element: series, axes, legend, etc. You should also call the positioning code at the OnZoom, OnUndoZoom and OnScroll events. At the forums threads below you'll find some examples on how to set custom positions:
http://www.teechart.net/support/viewtopic.php?t=4770
http://www.teechart.net/support/viewtopic.php?t=1758
If this doesn't help don't hesitate to let us know.
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
I have tried several of the examples and I can't seem to get it right. First, I don't really need to toe the Annotation to a Series Point. I just need it to stay in the correct position on the chart when the chart is scrolled. I tried the Axis->Left->CalcPos() in the MouseMove event. I can redraw the Annotation, but it draws at the very top of the chart in small vertical increments relative to the mouse moves.
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Kev,
You can try doing something like in the example below where ChartTool1 is an annotation tool, ChartTool2 is a nearest point tool and the annotation tool is positioned when pressing middle mouse button as, by default, left and right buttons are for zooming and scrolling respectively.
You can try doing something like in the example below where ChartTool1 is an annotation tool, ChartTool2 is a nearest point tool and the annotation tool is positioned when pressing middle mouse button as, by default, left and right buttons are for zooming and scrolling respectively.
Code: Select all
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Chart"
#pragma link "Series"
#pragma link "TeeComma"
#pragma link "TeEngine"
#pragma link "TeeProcs"
#pragma link "TeeTools"
#pragma resource "*.dfm"
TForm1 *Form1;
int tmpLeft, tmpTop, tmpIndex;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
ChartTool1->Active=false;
ChartTool2->Active=false;
Series1->FillSampleValues();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Chart1MouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if (Button==mbMiddle)
{
ChartTool1->Active=true;
ChartTool1->Shape->CustomPosition=true;
ChartTool1->Shape->Left=X;
ChartTool1->Shape->Top=Y;
TMetaClass* object;
tmpIndex = ChartTool2->GetNearestPoint(object, Series1,X,Y);
tmpLeft=X-Series1->CalcXPos(tmpIndex);
tmpTop=Y-Series1->CalcYPos(tmpIndex);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Chart1Scroll(TObject *Sender)
{
SetAnnotationPosition();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Chart1UndoZoom(TObject *Sender)
{
Chart1->Draw();
SetAnnotationPosition();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Chart1Zoom(TObject *Sender)
{
Chart1->Draw();
SetAnnotationPosition();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetAnnotationPosition()
{
ChartTool1->Shape->CustomPosition=true;
ChartTool1->Shape->Left=Series1->CalcXPos(tmpIndex)+tmpLeft;
ChartTool1->Shape->Top=Series1->CalcYPos(tmpIndex)+tmpTop;
}
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |