TeeChart demos

The Getting Started section of the TeeChart User Guide explains the most basic TeeChart procedures. Another useful place to look for help are the examples in the demo files.

Location of TeeChart demos

Open in Examples folder below the TeeChart installation folder to access the TeeChart demo projects.

There are many included forms in the TeeChart examples.

Each form shows a specific TeeChart feature or Series type.

Many Forms contain Delphi and C++ Builder source code to show event handling or interactive Charting.

The following example shows how to add data to a Chart by code and scroll the Series with the new point:

Note:

The flexibility of TeeChart’s components offers the ability to change Series type at any time - thus Series names by default are generic, Series1, Series2, etc..

Add a TeeChart to a Form and select the Editor ‘Add’ button to add a LineSeries

Click on Form.OnCreate or switch to source code to see the following:

procedure TScrollForm.FormCreate(Sender: TObject);
begin
  FillDemoPoints;
end;

procedure TScrollForm.FillDemoPoints;
var t : Integer;
begin
  { fill the LineSeries with some random data }
  Series1.Clear; { <-- this removes all points from Series1 }

  { let's add 60 minutes from 12:00 to 12:59 }
  for t:= 0 to 59 do
      AddXY( EncodeTime( 12, t, 0,0),Random(100),’’,clRed );

  { let's add 60 more minutes from 13:00 to 13:59 }
  for t:= 0 to 59 do
      AddXY( EncodeTime( 13, t, 0,0),Random(100),’’,clRed);
end;

This code will Clear LineSeries and plot two hours of random values from 0 to 100.

Because it is placed on the Form.OnCreate event, each time the form is shown, this code is executed.

Double click the Button1 component to see its associated OnClick code:

procedure TScrollForm.Button1Click(Sender: TObject);
var h,m,s,msec : Word;
begin
  if CheckBox1.Checked then { If VERTICAL SCROLL }
     DecodeTime( Series1.YValues.Last , h, m, s, msec)
  else
     DecodeTime( Series1.XValues.Last , h, m, s, msec);

  { add a new random point to the Series (one more minute) }
  Inc(m);
  if m=60 then
  begin
    m:=0;
    Inc(h);
  end;
  AddXY( EncodeTime( h, m, s, msec), Random(100),’’, clYellow );

end;

This code increments the last added point Time by one more minute.

The incremented Time value is added to the LineSeries, thus giving a new point.

The next code sample shows the key purpose of the example:

How to scroll the Horizontal Axis as new Points are added to the end ?

The easy way is to type the following code at the Series.OnAfterAdd event. This event is called each time a new point is added to the Series.

In this example, we scale the bottom horizontal Chart axis to show 55 minutes prior to the last point and 5 minutes after the last point.

{ This is the event we need to arrange Axis scale as new points are added. }

procedure TScrollForm.LineSeries1AfterAdd(Sender: TChartSeries;
  ValueIndex: Integer);
begin
 { If VERTICAL SCROLL }
  if CheckBox1.Checked then
  begin
    With Sender.GetVertAxis do  { <-- with the                                     Vertical Axis... }
    Begin
      Automatic := False;        { <-- we don’t want                                 automatic scaling }

{ In this example, we will set the Axis Minimum and Maximum values to

show One Hour of data ending at last point Time plus 5 minutes }
      Minimum := 0;
      Maximum := Sender.YValues.MaxValue +  
                 DateTimeStep[ dtFiveMinutes ];
      Minimum := Maximum - DateTimeStep[ dtOneHour ];
    end;

end

A great deal of flexibility can be achieved by manually setting the Axis properties.

Each Chart component has four standard front plane axes: LeftAxis, TopAxis, RightAxis and BottomAxis and one Depth axis, DepthAxis. Each Axis has a boolean "Automatic" property that defaults to True, meaning TeeChart will always calculate the Minimum and Maximum values for each Axis. In addition to the Standard axes you may add as many Custom axes as you wish, horizontall or vertically.

The Axis Minimum and Maximum properties are of type double, allowing float numbers or DateTime representations like "Date", "Time", "Now" or any other valid datetime value.

Now, compile and execute this project and look at each sample form in the TeeChart example project.

They should give you ideas that you can apply to your projects while you learn about TeeChart features.

The TEECHART.HLP file describes each component property in detail, with some source code examples mostly taken from the TeeChart demo projects.

We suggest that you to experiment with each different sample form and create new small projects to test TeeChart with your real data.