Create a Custom Component Descendant from DBChart

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
McMClark
Newbie
Newbie
Posts: 50
Joined: Thu Apr 15, 2004 4:00 am

Create a Custom Component Descendant from DBChart

Post by McMClark » Wed Feb 08, 2006 8:35 pm

I have written a component descendent from dbChart. I want wo have a ScrollBox that my user can add as many dbCharts as they want. Each dbChart could be populated by data from different queries. I am having a problem getting the series XValue and the ToopTipMark Text. I have provided the code below. Can someone look at the code and suggest what I might have written incorrectly.

unit MultiDBChart;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls, DBChart, Forms,
nxDB, Series, TeeProcs, TeEngine, Chart, DBCtrls, StdCtrls,
TeeTools, Math, Graphics, Dialogs;

type
TMultiDBChart = class(TScrollBox)
Series1: TLineSeries;
ChartTool1: TMarksTipTool;
procedure ChartTool1GetText(Sender: TMarksTipTool; var Text: string);
procedure ChartTool1Change(Sender: TCursorTool; x, y: Integer;
const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
function Series1GetPointerStyle(Sender: TChartSeries;
ValueIndex: Integer): TSeriesPointerStyle;
private
nOnClickChart : TNotifyevent;
procedure DoOnClick(Sender : TObject);
public
DBCharts : array of TDBChart;
function Add(intPositionCharts:integer;Chart_Query1:TNXQuery): integer;
published
property OnClickChart: TNotifyEvent read nOnClickChart write nOnClickChart;
end;
procedure Register;

Var
l: integer;

implementation

procedure Register;
begin
RegisterComponents('Additional', [TMultiDBChart]);
end;

procedure TMultiDBChart.DoOnClick(Sender : TObject);
begin

//nOnClickChart(sender);
end;

function TMultiDBChart.Add(intPositionCharts:integer;Chart_Query1:TNXQuery): integer;
Var
strSubject: String;
tmpPointSeries: TPointSeries;
intList: integer;
begin
l:=Length(DBCharts);
SetLength(DBCharts,l+1);
DBCharts[l]:=TDBChart.create(self);
strSubject := Chart_Query1.FieldByName('Subject').asString;
DBCharts[l]:=TDBChart.create(self);
with DBCharts[l] do
begin
//OnGetPointerStyle:=Series1GetPointerStyle;
parent := self;
Onclick := DoOnClick;
Top := intPositionCharts;
Height := 161;
DBCharts[l].BottomAxis.Visible := False;
DBCharts[l].Legend.Visible := False;
DBCharts[l].Tools.Add(TCursorTool.Create(self));
(DBCharts[l].Tools.Items[0] as TCursorTool).FollowMouse:=true;
(DBCharts[l].Tools.Items[0] as TCursorTool).OnChange:=ChartTool1Change;
(DBCharts[l].Tools.Items[0] as TCursorTool).Style:=cssVertical;
//set width height and posittion of DBChart here.
end;
tmpPointSeries := TPointSeries.Create(self);
DBCharts[l].AddSeries(tmpPointSeries);
With tmpPointSeries do
Begin
DataSource:= Chart_Query1;
YValues.ValueSource := 'Score';
XLabelsSource := 'DocumentName';
Pointer.Visible := True;
Title := strSubject;
CheckDataSource;
OnGetPointerStyle:=Series1GetPointerStyle;
end;

result := l;

end;

function TMultiDBChart.Series1GetPointerStyle(
Sender: TChartSeries; ValueIndex: Integer): TSeriesPointerStyle;
var
tmp: integer;
dbValue: Double;
strSeriesName: String;
intValue: integer;
intList: integer;
begin
strSeriesName := Sender.Title;
tmp:=Sender.YValues.Locate(Sender.YValue[ValueIndex]);
intValue := Trunc(Sender.YValue[ValueIndex]);
Case intValue of
1: begin
Sender.ValueColor[ValueIndex] := clWhite;
end;
2: begin
Sender.ValueColor[ValueIndex]:= clPurple;
end;
3: begin
Sender.ValueColor[ValueIndex]:= clOlive;
end;
4: begin
Sender.ValueColor[ValueIndex]:= clYellow;
end;
5: begin
Sender.ValueColor[ValueIndex]:= clBlue;
end;
else
begin
Sender.Valuecolor[ValueIndex]:=clGreen;
end;
end;
//Sender.ValueColor[ValueIndex] := clYellow;
result:=psRectangle;


end;

procedure TMultiDBChart.ChartTool1GetText(
Sender: TMarksTipTool; var Text: string);
begin
ShowMessage(Text);
end;

procedure TMultiDBChart.ChartTool1Change(Sender: TCursorTool; x, y: Integer;
const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
Var
strValue: String;
intList: integer;

begin

try
if ValueIndex > -1 then
begin
strValue := FloatToStr(Series.XValue[ValueIndex]);
if strValue <> '' then
begin
strValue := FloatToStr(Series.XValue[ValueIndex]);
end;
end;
except
end;

try
for intList := 0 to l do
begin
DBCharts[intList].Draw;
end;
except
end;
end;

end.

Post Reply