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 10.2 Tokyo > TeeChart > 系列の描画座標を取得する

Last updated at Posted at 2019-09-07
動作環境
RAD Studio 10.2 Tokyo Update 3
TeeChart Standard v2016.17.160129 32bit VCL

概要

  • TeeChartのSeries1の描画座標を取得する
    • SVG出力などに使う

実装例

Series1に対する関数を入力補完中にCalcXPos()を見つけた。

Unit1.cpp
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	int len = Series1->Count();

	float xval, yval;
	int xpos, ypos;
	String msg;

	for(int idx=0; idx < len; idx++) {
		xval = Series1->XValue[idx];
		yval = Series1->YValue[idx];
		xpos = Series1->CalcXPos(idx);
		ypos = Series1->CalcYPos(idx);
		msg = String().sprintf(L"%.2f, %.2f at %d, %d", xval, yval, xpos, ypos);
		Memo1->Lines->Add(msg);
	}
}

コード全部

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.Series.hpp>
#include <VclTee.TeeGDIPlus.hpp>
#include <VCLTee.TeEngine.hpp>
#include <VCLTee.TeeProcs.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE で管理されるコンポーネント
	TChart *Chart1;
	TButton *Button1;
	TLineSeries *Series1;
	TMemo *Memo1;
	void __fastcall Button1Click(TObject *Sender);
private:	// ユーザー宣言
public:		// ユーザー宣言
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

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

#include <vcl.h>
#pragma hdrstop

#include <memory>
#include <DateUtils.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
	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);
	}

	//
	Memo1->Lines->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	int len = Series1->Count();

	float xval, yval;
	int xpos, ypos;
	String msg;

	for(int idx=0; idx < len; idx++) {
		xval = Series1->XValue[idx];
		yval = Series1->YValue[idx];
		xpos = Series1->CalcXPos(idx);
		ypos = Series1->CalcYPos(idx);
		msg = String().sprintf(L"%.2f, %.2f at %d, %d", xval, yval, xpos, ypos);
		Memo1->Lines->Add(msg);
	}
}
//---------------------------------------------------------------------------

実行例

2019-09-08_08h55_58.png

0
1
2

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?