Recent

Author Topic: Newbie TAchart Problem  (Read 13513 times)

acp693

  • Jr. Member
  • **
  • Posts: 73
Newbie TAchart Problem
« on: June 16, 2009, 06:42:56 pm »
Hi I'm new to Pascal and Lazarus. I already built a calculator with Lazarus to try out the Pascal language and am enjoying it a lot.

Last night I tried charts. I placed a button and a TChart on a form and copied the code from this page on the wiki
http://wiki.lazarus.freepascal.org/TAChart/de , but I get compilation errors.  Any help would be gratefully received.

I'm using Lazarus IDE v0.9.26.2-0 , FPC version 2.2.2 ,  i386-linux-gtk 2 (beta)
on Debian Lenny 5.0.

Albert

unit1.pas(34,17) Error: Identifier not found "TTASerie"
unit1.pas(34,17) Error: Error in type definition
unit1.pas(39,16) Error: Identifier not found "TTASerie"
unit1.pas(40,22) Error: Incompatible type for arg no. 1: Got "<erroneous type>", expected "TComponent"
tagraph.pas(1273,18) Hint: Found declaration: TChart.AddSerie(TComponent)
unit1.pas(41,7) Error: Illegal qualifier
unit1.pas(42,7) Error: Illegal qualifier
unit1.pas(43,7) Error: Illegal qualifier
unit1.pas(45,10) Error: Illegal qualifier
unit1.pas(54) Fatal: There were 8 errors compiling module, stopping

This is my code:
Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  TAGraph, StdCtrls, TACHartUtils;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Chart1: TChart;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
  Serie:TTASerie;
  i:Integer;


begin
Serie:=TTASerie.Create(Chart1);
Chart1.AddSerie(Serie);
Serie.ShowLines:=True;
Serie.ShowPoints:=False;
Serie.Title:='Sinus';
for i:=-500 to 499 do
   Serie.AddXY(i/10,Sin(i/10)*10,clBlack);

end;

initialization
  {$I unit1.lrs}

end.
                                                                       

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Newbie TAchart Problem
« Reply #1 on: June 16, 2009, 10:48:25 pm »
I think "Chart1: TChart;" would be "Chart1: TTAChart;",
but I can't test it now because I haven't my notebook with Lazarus here now.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
Re: Newbie TAchart Problem
« Reply #2 on: June 17, 2009, 08:26:47 am »
The German wiki page is outdated, the English wiki page is up to date.

Instead of having this code, it refers to the demos that are distributed with the component.

alanphys

  • Jr. Member
  • **
  • Posts: 56
Re: Newbie TAchart Problem
« Reply #3 on: June 17, 2009, 08:39:17 am »
Add unit TASeries to your uses

Cheers

Alanphys
Alanphys
Fedora 34 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

acp693

  • Jr. Member
  • **
  • Posts: 73
Re: Newbie TAchart Problem
« Reply #4 on: June 17, 2009, 11:27:31 am »
Thanks, I added TASeries to the uses but that doesn't make any difference, Nor does the suggestion by Blaazen.

I'm quite confused by the chart system in Lazarus. I see references to TChart and TAChart, but only a widget for TChart, Does TAChart use the TChart widget?

last night I also looked at the demo of TAChart found in Components/TAChart. I don't understand How this demo works, The demo unit  itself is called TAGraph, is this the same TAGraph that gets added to uses when I place a TChart on a form?  After compilation there appears a gui with buttons checkboxes etc.
However, in unit TAGraph I can't find any code that builds this gui?  Any thoughts?

regards

Albert

alanphys

  • Jr. Member
  • **
  • Posts: 56
Re: Newbie TAchart Problem
« Reply #5 on: June 17, 2009, 01:49:44 pm »
The TAChart demo is in TAChart/demo. The project file is demo.lpi and the gui is defined by unit1.pas and unit1.lfm. If you can compile and run this you are on your way.

The file TAChart defines, among other things, the TChart type and is used by the Lazarus package. This is the widget you see on the toolbar. When you place it in your form it defines a TChart component. So your Chart1:TChart is correct!

I'm not sure why the authors called the package TAChart. I think it was to distinguish it from the orginal TeeChart by Steema Software which was released for Lazarus at one stage but seems to have disappeared again.

Just looking at your code again it should run if you have added TASeries. You shouldn't need TAChartUtils. This may be the cause of the confusion. Here is an excerpt from one of my apps:

Code: [Select]
unit ProfileUnit;
{modified to use TAChart}

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Menus,
  ExtCtrls, StdCtrls, Buttons, TAGraph, TASeries;

type

  { TProfile }

  TProfile = class(TForm)
     bbClose: TBitBtn;
     bbCorrMap: TBitBtn;
     bbCorrelation: TBitBtn;
     bbDist: TBitBtn;
     bbMTF: TBitBtn;
     bbProfile: TBitBtn;
     ProfileChart: TChart;
     ebWidth: TEdit;
     ebOffset: TEdit;
     Label1: TLabel;
     Label2: TLabel;
     pfOpenDialog: TOpenDialog;
     pfSaveDialog: TSaveDialog;
     XYProfile: TGroupBox;
     MainMenu1: TMainMenu;
     miCorrMap: TMenuItem;
     miCorrelation: TMenuItem;
     miDist: TMenuItem;
     miMTF: TMenuItem;
     miProfile: TMenuItem;
     miPlot: TMenuItem;
     miSave: TMenuItem;
     miOpen: TMenuItem;
     miFile: TMenuItem;
     Panel1: TPanel;
     ProfileData: TSerie;
     rbXProfile: TRadioButton;
     rbYProfile: TRadioButton;
     procedure bbMTFClick(Sender: TObject);
     procedure miCorrMapClick(Sender: TObject);
     procedure miCorrelationClick(Sender: TObject);
     procedure miDistClick(Sender: TObject);
     procedure miOpenClick(Sender: TObject);
     procedure miProfileClick(Sender: TObject);
     procedure miSaveClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Profile: TProfile;

implementation

var Reconfile: string;

{ TProfile }

procedure TProfile.miProfileClick(Sender: TObject);
var I,J,
    X,Y,
    W:   integer;
    Counts: array[1..512] of double;

begin
Screen.Cursor := crHourGlass;
if ProfileData <> nil then ProfileData.Free;
ProfileData := TSerie.Create(ProfileChart);
ProfileChart.AddSerie(ProfileData);
ProfileData.Clear;
ProfileChart.Clean;
ProfileChart.LeftAxis.Title.Caption := 'Counts';
ProfileChart.BottomAxis.Title.Caption := 'Profile';
W := StrToInt(ebWidth.Text);
X := Detector.XRes;
Y := Detector.YRes;
for I:=1 to 512 do Counts[I] := 0;
if rbXProfile.Checked then
   begin
   ProfileChart.Title.Text.Clear;
   ProfileChart.Title.Text.Add('X Profile');
   for I:=1 to W do
      for J:=1 to X do
         begin
         Counts[J] := Counts[J] + Detector.Data[(I - 1 + Y div 2 - W div 2)
            *2*X + J*2 - 1];
         end;
   for I:=1 to X do ProfileData.AddXY(I,Counts[I],'',clRed);
   end
  else
   begin
   ProfileChart.Title.Text.Clear;
   ProfileChart.Title.Text.Add('Y Profile');
   for I:=1 to W do
      for J:=1 to Y do
         begin
         Counts[J] := Counts[J] + Detector.Data[(J - 1)*2*X + (I + X div 2 -
            W div 2)*2 - 1]
         end;
   for I:=1 to Y do ProfileData.AddXY(I,Counts[I],'',clRed);
   end;
Screen.Cursor := crDefault;
end;

end.
Alanphys
Fedora 34 + KDE/QT5, Tinycore 8, Windows XP-10
https://github.com/alanphys

acp693

  • Jr. Member
  • **
  • Posts: 73
Re: Newbie TAchart Problem
« Reply #6 on: June 17, 2009, 03:17:26 pm »
Ah, thankyou alanphys,
That's great. I can see what's happening now.

Thanks again.

Albert


 

TinyPortal © 2005-2018