LoginSignup
0
0

More than 5 years have passed since last update.

C++ Builder XE4 > TeeChart > 多量のプロットの描画高速化 > 実行可能コード (2019-04-11版)

Last updated at Posted at 2019-04-11
動作環境
C++ Builder XE4

2016年3月31日の記事 > 分かりにくい

上記を参考に実装を進めようとしたが、分かりにくい。

さらに、実装ミスも見つかった。

もう、ほんと、ねぇ。

実行可能コード (2019-04-11版)

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;
    TFastLineSeries *Series1;
    TButton *Button1;
    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::Button1Click(TObject *Sender)
{
    Chart1->Series[0]->XValues->DateTime = true;
    Chart1->BottomAxis->DateTimeFormat = L"nn:ss";

    TDateTime dt;

    dt = Now();

    int cnt = 0;
    TDoubleDynArray xs, ys;

    // 1. 既存データの読込み
    xs.Length += Series1->XValues->Count;
    ys.Length += Series1->XValues->Count;
    for(int idx=0; idx < Series1->XValues->Count; idx++) {
        xs[cnt] = Series1->XValues->Value[idx];
        ys[cnt] = Series1->YValues->Value[idx];
        cnt++;
    }

    // 2. 追加
    const int numData = 10;  // 追加データの個数
    xs.Length += numData;
    ys.Length += numData;
    double yval;
    for (int idx=0; idx < numData; idx++) {
        yval = (1+ idx) % 2;
        xs[cnt] = dt;
        ys[cnt] = yval;
        cnt++;
        //
        dt = IncMilliSecond(dt, 100);
    }
    Series1->XValues->Value = xs;
    Series1->XValues->Count = cnt;
    Series1->XValues->Modified = true;
    Series1->YValues->Value = ys;
    Series1->YValues->Count = cnt;
    Series1->YValues->Modified = true;

    Series1->Repaint();  // 描画の更新に必要
}
//---------------------------------------------------------------------------

実行例

  • ボタンを数秒おきに押下した結果が以下

2019-04-11_19h46_57.png

備考 > 資料として

  • 動くことを確認したコードを載せること
  • 閲覧者に分かりやすい書き方にすること
  • 「40秒で支度しな」に答えられるように
0
0
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
0