Page 1 of 1

TBarSeries

Posted: Wed Jan 28, 2004 12:36 pm
by 8574417
Hi

I'm trying to make a bar series with the different segments having a different color AND BRUSH STYLE. Using the AddXY funtion allows me to add values and specifying a color, but how to specify a Brush style only to be used for the specific value. When I use the TBarSeries.Brush or TBarSeries.BarBrush properties I set ALL of the values.....

Here is my test example. put a button and a Chart on the form, set the chart's View3D property set to false:

Hope somone has an answer !

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, TeeProcs, TeEngine, Chart, Series,TeCanvas;
type
//
TLayer = record
Depth : Single;
Color : TColor;
Text : String;
end;
TLayers = array of TLayer;

TForm1 = class(TForm)
Chart1: TChart;
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
I : integer;
NLay : Integer;
Layers : TLayers;
Series : TBarSeries;
begin
NLay := 5;
//Make the Bar serie
Chart1.FreeAllSeries();
Series := TBarSeries.Create(Chart1);
Series.ParentChart := Chart1;
Series.MultiBar := mbNone;
Series.Marks.Visible := False;
Series.UseYOrigin := True;
for I := NLay downto 0 do begin
Series.AddXY(100, I*10,'Layer : ' +IntToStr(I),clGreen);
if I=1 then begin
with Series.BarBrush do begin
Color := clYellow;
Style := bsSolid;
end;
end else begin
with Series.BarBrush do begin
Color := clYellow;
Style := bsDiagCross;
end;
end;
end;
end;

end.

P.S.

Posted: Wed Jan 28, 2004 12:39 pm
by 8574417
I'm using TeeChart Pro 5 VCL version v5.01 !

BarSeries Answer

Posted: Wed Jan 28, 2004 3:19 pm
by 8574417
Hi,

After some experimenting I found a solution - if anybody should be interested, here it is:

I add an object list as a global property, and acces this in the Series1GetBarStyle. Works nicely


-tb

heres the code:




unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, TeeProcs, TeEngine, Chart, Series,TeCanvas,Contnrs;
type
TForm1 = class(TForm)
Chart1 : TChart;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
FBrushList : TObjectList;
procedure Series1GetBarStyle(Sender: TCustomBarSeries; ValueIndex: Integer; var TheBarStyle: TBarStyle);
public
//
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
I : integer;
NLay : Integer;
Series : TBarSeries;
Style : TBrushStyle;
Brush : TChartBrush;
BM : TBitMap;
begin
//Make the Bar serie
Chart1.FreeAllSeries();
FBrushList.Clear;
Series := TBarSeries.Create(Chart1);
Series.ParentChart := Chart1;
Series.CustomBarWidth := 30;
Series.MultiBar := mbNone;
Series.Marks.Visible := False;
Series.UseYOrigin := True;
Series.Title := 'ged';
Series.OnGetBarStyle := Self.Series1GetBarStyle;
NLay := 15;
for I :=NLay-1 downto 0 do begin
//Here I add whatever style I wish the layer to have
Brush := TChartBrush.Create(nil);
case I of
0 : Brush.Style:=bsFDiagonal;
3 : Brush.Style:=bsHorizontal;
5 : Brush.Style:=bsVertical;
8 : Brush.Style:=bsBDiagonal;
10: Brush.Image.LoadFromFile('tst.bmp');
12: Brush.Style:=bsCross;
14: Brush.Style:=bsDiagCross;
else
Brush.Style:=bsSolid;
end;
FBrushList.Add(Brush);
Series.AddXY(100, (I+10)*5,'Lag ',clGreen);
end;

end;

procedure TForm1.Series1GetBarStyle(Sender: TCustomBarSeries; ValueIndex: Integer; var TheBarStyle: TBarStyle);
begin
Sender.Brush := (FBrushList[ValueIndex] as TChartBrush);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
FBrushList := TObjectList.Create;
FBrushList.OwnsObjects := True;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
FBrushList.Free;
end;

end.