動作環境
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);
}
}
//---------------------------------------------------------------------------