TeeChartの使い方 折れ線グラフ作成

TeeChartの使い方 折れ線グラフ作成 (TeeChart Pro 8.06)

uessに Series, TeEngineを追加

procedure TForm1.a;
var
   i: Integer;
   Series1: TFastLineSeries; //折れ線(2D)
   Series2: TLineSeries; //リボン(3D)
begin

    Chart1.SeriesList.Clear;

    //Y軸用シリーズを作成
    Series1 := TFastLineSeries.Create(Self);
    Series1.ParentChart := Chart1;
    Series1.VertAxis := aLeftAxis; // 主軸
    Series1.XValues.Order := loAscending; //(loNone, loAscending, loDescending)
    Series1.YValues.Order := loNone; //(loNone, loAscending, loDescending)
    Series1.Active := False;
    Series1.Title := ‘a’;
    Series1.Color := clBlue;
    Series1.Pen.Width := 1;
    Series1.Pen.Style := psSolid;

    //高速化のための設定(通常は必要ないと思われる)===========
    //Falseにすると異なるXピクセル位置を持つポイントのみ描画して高速化

    Series1.DrawAllPoints := False;
    //描画速度向上
    Series1.AutoRepaint := False;//FastPenを有効にするため
    Series1.FastPen := True;
    //データー追加時の速度向上(ソートしない)
    Series1.XValues.Order := loNone;
    //GDIオーバーフローをチェックしないことにより高速化
    //ズームを多用する場合は要注意?

    Chart1.Axes.FastCalc := True;
    //=====================================================

    //データーを追加
    for i := 0 to 100 – 1 do
    begin
      Series1.AddXY(i, Random(10));
    end;
    //シリーズを有効化
    Series1.Active := True;

    //第2Y軸用 シリーズを作成
    Series2 := TLineSeries.Create(Self);
    Series2.ParentChart := Chart1;
    Series2.VertAxis := aRightAxis; // 第2軸
    Series2.XValues.Order := loAscending; //(loNone, loAscending, loDescending)
    Series2.YValues.Order := loNone; //(loNone, loAscending, loDescending)
    Series2.Active := False;
    Series2.Title := ‘b’;
    Series2.Color := clRed;
    Series2.LinePen.Width := 1;
    Series2.LinePen.Style := psSolid;
    Series2.LinePen.Color := clYellow;
    Series2.Dark3D := True; //リボンの裏の色を濃くする

    for i := 0 to 100 – 1 do
    begin
      Series2.AddXY(i, Random(10) + 10);
    end;
    Series2.Active := True;

end;

2009.12.24追記: 線の途切れを作るには,AddNullXYメソッドを使用する. Series2.AddNullXY(x, y, ”)
ただしこれはFastLineSeriesでは使えない.LineSeriesで使用する.

2009.12.27 (2009.12.24追記の訂正):
FastLineSeriesの場合でも,
Series1.IgnoreNulls := false;
Series1.TreatNulls := tnDontPaint;
を設定することでAddNullXYメソッドが有効になる.

Aero対応のためのMainFormOnTaskbarプロパティー注意点

Aero対応にするには,プロジェクトソースにMainFormOnTaskbar := Trueを記述する必要がある.
しかしこうするとメインフォームから表示したフォームが常にメインフォームの上に表示されてしまうので要注意.
必要に応じてTrueかFalseが選択する.実行時に変更してはいけない.
Delphi2007以降では新規アプリケーション作成時に自動的にMainFormOnTaskbar := Trueが記述される.

program Project1;

uses
  Forms,
  Unit1 in ‘Unit1.pas’ {Form1},
  Unit2 in ‘Unit2.pas’ {Form2};

{$R *.res}

begin
  {$WARN SYMBOL_PLATFORM OFF}
    //メモリーリークチェック
    ReportMemoryLeaksOnShutdown := DebugHook <> 0;
  {$WARN SYMBOL_PLATFORM ON}
  Application.Initialize;
  //これがあるとForm1がForm2の裏に隠れる
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.

参考:http://docwiki.embarcadero.com/VCL/ja/Forms.TApplication.MainFormOnTaskBar (VCL Documentation)

TeeChartの使い方 軸設定

TeeChartの使い方 軸設定 (TeeChart Pro 8.06)

    With Chart1 do
    begin

        //Y軸
       LeftAxis.Title.Font.Size := 11;
       LeftAxis.Title.Caption := ‘Y-axis’;
       LeftAxis.LabelsFont.Size := 11;
       LeftAxis.AxisValuesFormat := ‘0.0##’;
       LeftAxis.Minimum := 0;
       LeftAxis.AutomaticMaximum := True;
       LeftAxis.AutomaticMinimum := False;
       //LeftAxis.Automatic := True;
       LeftAxis.Ticks.Visible := True;//目盛表示
       LeftAxis.TickLength := 5;//目盛の長さ
       LeftAxis.TicksInner.Visible := True;//内側目盛表示
       LeftAxis.TickInnerLength := 2;//内側目盛の長さ
       LeftAxis.MinorTicks.Visible := True;//副目盛表示
       LeftAxis.MinorTickLength := 3;//副目盛の長さ
       LeftAxis.Grid.Visible := True;//グリッド表示
       //目盛増加量(グリッド間隔) 小さすぎる場合は勝手に大きくなる
       LeftAxis.Increment := 0.5;
       //グリッド間隔が勝手に大きくなるのをなるべく防ぐには次のようにする
       LeftAxis.LabelsSeparation := 0;

       //第2Y軸
       RightAxis.Title.Font.Size := 11;
       RightAxis.Title.Caption := ‘2nd Y-axis’;
       RightAxis.LabelsFont.Size := 11;
       RightAxis.AxisValuesFormat := ‘0.0##’;
       RightAxis.Minimum := 0;
       RightAxis.Automatic := True;
       RightAxis.Grid.Visible := False;

       //X軸
       BottomAxis.Title.Font.Size := 11;
       BottomAxis.Title.Caption := ‘X-axis’;
       BottomAxis.LabelsFont.Size := 11;
       BottomAxis.AxisValuesFormat := ‘0’;
       BottomAxis.Automatic := True;
       BottomAxis.Grid.Visible := True;

   end;