home *** CD-ROM | disk | FTP | other *** search
- {*********************************************}
- { TeeChart Moving Bars example }
- { Copyright (c) 1995-1998 by David Berneda }
- { All rights reserved }
- {*********************************************}
- unit UMoveBar;
- {$P-} { <-- this is for Delphi 1.0 compatibility }
-
- interface
-
- uses
- WinTypes,WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- TeEngine, Series, ExtCtrls, TeeProcs, Chart, StdCtrls;
-
- { TeeChart Pro.
- Example showing the Bar series BarWidthPercent and CustomBarWidth
- properties.
-
- Also showing how to allow user run-time moving of Bars, both for
- X and Y directions.
- }
- type
- TFormMoveBars = class(TForm)
- Chart1: TChart;
- Series1: TBarSeries;
- CheckBox1: TCheckBox;
- Label1: TLabel;
- ScrollBar1: TScrollBar;
- Label2: TLabel;
- Label3: TLabel;
- ScrollBar2: TScrollBar;
- Label4: TLabel;
- Series2: TFastLineSeries;
- Button1: TButton;
- CheckBox2: TCheckBox;
- Label5: TLabel;
- Label6: TLabel;
- procedure FormCreate(Sender: TObject);
- procedure CheckBox1Click(Sender: TObject);
- procedure ScrollBar1Change(Sender: TObject);
- procedure Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
- ValueIndex: Longint; var LabelText: String);
- procedure ScrollBar2Change(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure CheckBox2Click(Sender: TObject);
- procedure Chart1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure Chart1MouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- private
- { Private declarations }
- public
- { Public declarations }
- tmpBar:Integer;
- end;
-
- implementation
-
- {$R *.DFM}
-
- procedure TFormMoveBars.FormCreate(Sender: TObject);
- begin
- { fill the Bar series with sample values specifying X coordinates }
- With Series1 do
- begin
- Clear;
- AddXY( 0, 100, '', clTeeColor);
- AddXY( 3, 200, '', clTeeColor);
- AddXY( 7, 300, '', clTeeColor);
- AddXY( 11, 400, '', clTeeColor);
- AddXY( 15, 500, '', clTeeColor);
- AddXY( 22, 600, '', clTeeColor);
- AddXY( 30, 700, '', clTeeColor);
-
- ColorEachPoint:=True;
- end;
-
- { fill the Line series with sample values specifying X coordinates }
- With Series2 do
- begin
- Clear;
- AddXY( 0, 100, '', clTeeColor);
- AddXY( 3, 200, '', clTeeColor);
- AddXY( 7, 300, '', clTeeColor);
- AddXY( 11, 400, '', clTeeColor);
- AddXY( 15, 500, '', clTeeColor);
- AddXY( 22, 600, '', clTeeColor);
- AddXY( 30, 700, '', clTeeColor);
- end;
-
- { change the bottom axis (the X axis) labelling increment }
- With Chart1.BottomAxis do
- begin
- LabelStyle:=talValue;
- Increment:=1;
- LabelsSeparation:=0;
- end;
-
- { initialize the scrollbars }
- ScrollBar1.Position:=Series1.BarWidthPercent;
- ScrollBar2.Position:=Series1.CustomBarWidth;
-
- tmpBar:=-1;
- end;
-
- procedure TFormMoveBars.CheckBox1Click(Sender: TObject);
- begin
- Series1.SideMargins:=CheckBox1.Checked;
- end;
-
- procedure TFormMoveBars.ScrollBar1Change(Sender: TObject);
- begin
- { Call ScrollBar2Change to Set the CustomBarWidth property to Zero }
- ScrollBar2.Position:=0;
- ScrollBar2Change(Self);
-
- { change the "BarWidthPercent" property... }
- { BarWidth percent is allowed only then CustomBarWidth is zero (auto width) }
- Series1.BarWidthPercent:=ScrollBar1.Position;
- Label2.Caption:=IntToStr(ScrollBar1.Position)+'%';
- end;
-
- procedure TFormMoveBars.Chart1GetAxisLabel(Sender: TChartAxis;
- Series: TChartSeries; ValueIndex: Longint; var LabelText: String);
- var t:Integer;
- begin
- if Sender=Chart1.BottomAxis then
- With Chart1.BottomAxis do
- begin
- LabelsFont.Style:=[];
-
- { draw some axis labels with special Font... }
- for t:=0 to Series1.Count-1 do
- if LabelText=FormatFloat(AxisValuesFormat,Series1.XValues[t]) then
- begin
- LabelsFont.Style:=[fsBold];
- break;
- end;
- end;
- end;
-
- procedure TFormMoveBars.ScrollBar2Change(Sender: TObject);
- begin
- { change the "CustomBarWidth" property... }
- Series1.CustomBarWidth:=ScrollBar2.Position;
-
- if ScrollBar2.Position=0 then
- Label4.Caption:='(auto)'
- else
- Label4.Caption:=IntToStr(ScrollBar2.Position)+' pixels';
- end;
-
- procedure TFormMoveBars.Button1Click(Sender: TObject);
- begin
- Close;
- end;
-
- procedure TFormMoveBars.CheckBox2Click(Sender: TObject);
- begin
- Chart1.View3D:=CheckBox2.Checked;
- end;
-
- procedure TFormMoveBars.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- { calculate if user clicked on a Bar... }
- if Button=mbLeft then tmpBar:=Series1.Clicked(x,y);
- end;
-
- procedure TFormMoveBars.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- { when left mouse button is depressed, forget about moving bars... }
- tmpBar:=-1;
- end;
-
- procedure TFormMoveBars.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- begin
- if tmpBar<>-1 then { if moving a bar, change X and Y values... }
- With Series1 do
- begin
- XValues[tmpBar]:=XScreenToValue(X);;
- YValues[tmpBar]:=YScreenToValue(Y);
-
- { force repaint to see the bar moving... }
- Repaint;
- end;
- end;
-
- end.
-