Page 1 of 1
Using Domain Objects with TeeChart
Posted: Tue Nov 25, 2014 8:18 pm
by 16563710
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?
Re: Using Domain Objects with TeeChart
Posted: Thu Nov 27, 2014 9:29 am
by narcis
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.
Re: Using Domain Objects with TeeChart
Posted: Thu Nov 27, 2014 11:44 am
by narcis
Hi dras,
Also, there's
a post about domain objects that at the
Google + TeeChart preview community.