Using Domain Objects with TeeChart

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
dras
Newbie
Newbie
Posts: 5
Joined: Wed Oct 17, 2012 12:00 am

Using Domain Objects with TeeChart

Post by dras » Tue Nov 25, 2014 8:18 pm

We use TeeCharts extensively for the presentation of a graphical representation of real world objects. Creating Series with TChartValueLists leads to a duplication of data and issues with synchronization of data changes since there is no longer a single source of truth. Is it possible to use TeeChart with domain objects in a manner similar to DeveloperExpress with their custom datasource for grids where the grid asks the datasource for the data to display and the datasource can ask a dataset, domain object etc.

Alternatively, has anyone written a domain adapter that can quickly transfer minimal domain information to the chart for presentation?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Using Domain Objects with TeeChart

Post by Narcís » Thu Nov 27, 2014 9:29 am

Hi dras,

Yes, this is possible using reference types as I explained here. This is a .NET example but it also applies to Delphi:

Code: Select all

var
  Form1: TForm1;
  MyArray, CopyArray: Array of Double;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  MyArray[1] := 7;
  ShowMessage(FloatToStr(CopyArray[1]));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  SetLength(MyArray, 2);
  MyArray[0]:=1;
  MyArray[1]:=2;
  CopyArray := MyArray;
end;
The TeeChart example in Delphi is this:

Code: Select all

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, VclTee.TeeGDIPlus,
  VCLTee.TeEngine, Vcl.ExtCtrls, VCLTee.TeeProcs, VCLTee.Chart;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Chart1: TChart;
    Chart2: TChart;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure AddNewSeries(Chart: TChart);
    procedure ModifySeries(Series: TChartSeries);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  XValues, YValues: Array of Double;

implementation

{$R *.dfm}

uses VCLTee.Series;

procedure TForm1.AddNewSeries(Chart: TChart);
var Series1: TFastLineSeries;
begin
  Series1 := TFastLineSeries.Create(Self);
  Series1.ParentChart := Chart;

  Series1.XValues.Value := TChartValues(XValues);
  Series1.XValues.Count := Length(XValues);

  Series1.YValues.Value := TChartValues(YValues);
  Series1.YValues.Count := Length(YValues);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  YValues[1] := 7;
  ModifySeries(Chart1[0]);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D := False;
  Chart2.View3D := False;

  SetLength(XValues, 2);
  XValues[0] := 1;
  XValues[1] := 2;

  SetLength(YValues, 2);
  YValues[0] := 1;
  YValues[1] := 2;

  AddNewSeries(Chart1);
  AddNewSeries(Chart2);
end;

procedure TForm1.ModifySeries(Series: TChartSeries);
begin
  Series.XValues.Modified := True;
  Series.YValues.Modified := True;

  Series.Repaint;
end;

end.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Using Domain Objects with TeeChart

Post by Narcís » Thu Nov 27, 2014 11:44 am

Hi dras,

Also, there's a post about domain objects that at the Google + TeeChart preview community.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply