0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2018-11-18
動作環境
C++ Builder XE4
TeeChart Lite v2013.08.130414 32bit VCL

関連

処理概要

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

実装

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

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

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?