動作環境
C++ Builder XE4
TeeChart Lite v2013.08.130414 32bit VCL
関連
処理概要
- 系列データ(例: Series1)の特定のインデックス(例:5)に対応する(X,Y)座標を取得する
実装
CalcXPosValue()
とCalcYPosValue()
を使う。
Returns the pixel Screen Vertical coordinate of the specified Value.
...
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.TeEngine.hpp>
#include <VCLTee.TeeProcs.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE で管理されるコンポーネント
TChart *Chart1;
TButton *Button1;
TFastLineSeries *Series1;
TLabel *Label1;
void __fastcall FormCreate(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
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)
{
int idxSer = 0; // シリーズのインデックス. 1つ目のシリーズなので0
int idxDat = 5; // シリーズ中のデータポイントのインデックス (0始まり). 5: 任意の値
double xval = Series1->XValue[idxDat];
int xpos = Chart1->Series[idxSer]->CalcXPosValue(xval);
double yval = Series1->YValue[idxDat];
int ypos = Chart1->Series[idxSer]->CalcYPosValue(yval);
Label1->Left = xpos;
Label1->Top = ypos - 15; // 15: 調整用の値 (少し上に表示)
}
//---------------------------------------------------------------------------
動作
Button1押下後、Label1という表示がインデックス5の点の近くに表示される。
備考
似たような関数として以下がある。