Page 1 of 1

Chart Annotations

Posted: Fri Aug 31, 2007 3:53 am
by 9243548
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.

Posted: Fri Aug 31, 2007 8:02 am
by narcis
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.

Posted: Mon Sep 03, 2007 2:33 pm
by 9243548
I had thought that was the case. Can you give me an example of how to get the "Closest" Series Y value to where the mouse is when clicked? I would like to be able to click anywhere on the chart (not necessarily on a Series) and have an annotation tied to the closest series y value.

thanks,
kev

Posted: Mon Sep 03, 2007 10:22 pm
by 9243548
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.

Posted: Tue Sep 04, 2007 9:39 am
by narcis
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.

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;
}