C++ Builder XE4 > TeeChart > グラフのX軸、Y軸の座標(X,Y)を取得する > ChartRectを使う

```txt:動作環境
C++ Builder XE4
TeeChart Lite v2013.08.130414 32bit VCL
```

### 関連

- [C++ Builder XE4 > TeeChart > クリックした点に近い系列データの明示 > 点と値の表示](https://qiita.com/7of9/items/914c74e4682082124f24)
- [c++ builder XE4, 10.2 Tokyo > TeeChart > 最初の一歩 > グラフ作成まで](https://qiita.com/7of9/items/c0eb0b85583a197c8a47)

### 処理概要

- グラフのX軸、Y軸の座標を取得したい
- その座標情報は上記リンク記事の`Clicked(X, Y)`などで使う

### 実装

- [How find top/left and top/right of the Teechart graph and Teechart Canvas?](https://stackoverflow.com/questions/30672509/how-find-top-left-and-top-right-of-the-teechart-graph-and-teechart-canvas)

`ChartRect`を使うとのこと。


```Unit1.h
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <VCLTee.Chart.hpp>
#include <VCLTee.TeEngine.hpp>
#include <VCLTee.TeeProcs.hpp>
#include <VCLTee.Series.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE で管理されるコンポーネント
	TChart *Chart1;
	TFastLineSeries *Series1;
	TMemo *Memo1;
	TButton *Button1;
	void __fastcall FormCreate(TObject *Sender);
	void __fastcall Button1Click(TObject *Sender);
	void __fastcall Chart1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
          int X, int Y);
private:	// ユーザー宣言
public:		// ユーザー宣言
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

```

```Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include <DateUtils.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
    // ダミーデータの追加

    Chart1->Series[0]->XValues->DateTime = true;
    Chart1->BottomAxis->DateTimeFormat = L"nn:ss";

    TDateTime dt;

    dt = Now();

    double yval;
    for (int idx=0; idx < 10; idx++) {
        yval = (1+ idx) % 2;
        Series1->AddXY(dt, yval, "", clRed);
        dt = IncSecond(dt, 1);
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	Memo1->Lines->Clear();

	int xval, yval;
	String wrk;

	xval = Chart1->ChartRect.Left;
	wrk = "Left > X: " + IntToStr(xval);
	Memo1->Lines->Add(wrk);

	xval = Chart1->ChartRect.Right;
	wrk = "Right > X: " + IntToStr(xval);
	Memo1->Lines->Add(wrk);

	yval = Chart1->ChartRect.Top;
	wrk = "Top > Y: " + IntToStr(yval);
	Memo1->Lines->Add(wrk);

	yval = Chart1->ChartRect.Bottom;
	wrk = "Bottom > Y: " + IntToStr(yval);
	Memo1->Lines->Add(wrk);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Chart1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
          int X, int Y)
{
	String wrk = IntToStr(X) + L", " + IntToStr(Y);
	Memo1->Lines->Add(wrk);
}
//---------------------------------------------------------------------------
```

### 動作例

- Button1押下
- グラフの左Y軸上端をマウスクリック
- グラフの下X軸右端をマウスクリック

![2018-11-18_13h09_58.png](https://qiita-image-store.s3.amazonaws.com/0/32870/f2bc1c25-7d66-5f72-d638-a524670e93c0.png)

X軸の両端、Y軸の両端が`ChartRect`を使うことで取得できることが分かった。