📄 passingdata.pas
字号:
unit passingdata;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, OleCtrls, ChartfxLib_TLB, SfxBar_TLB;
type
TForm1 = class(TForm)
ChartFX1: TChartFX;
GroupBox1: TGroupBox;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
RadioButton4: TRadioButton;
RadioButton5: TRadioButton;
RadioButton6: TRadioButton;
RadioButton7: TRadioButton;
RadioButton8: TRadioButton;
RadioButton9: TRadioButton;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
procedure RadioButton1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure RadioButton3Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure RadioButton4Click(Sender: TObject);
procedure RadioButton5Click(Sender: TObject);
procedure RadioButton6Click(Sender: TObject);
procedure RadioButton7Click(Sender: TObject);
procedure RadioButton8Click(Sender: TObject);
procedure RadioButton9Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.RadioButton1Click(Sender: TObject);
VAR
i: Integer;
s: String;
begin
// Bars
With ChartFX1 Do Begin
// Start from original chart
Import(CHART_CFXOLEFILE, 'original.chd');
Gallery := BAR;
// Init data. 2 Series and 6 points means
OpenDataEx(COD_VALUES Or COD_REMOVE, 2, 6);
For i := 0 To 5 Do Begin
ValueEx[0, i] := 50 + Random(50); // First Bar in the group
ValueEx[1, i] := 50 + Random(50); // Second Bar in the group
Str(i+1,s);
Legend[i] := 'Label' + s;
end;
CloseData(COD_VALUES);
// Set color for each series
OpenDataEx(COD_COLORS, 2, 0);
Series[0].Color := RGB(0, 255, 0);
Series[1].Color := RGB(255, 0, 0);
CloseData(COD_COLORS);
// Series legend
Series[0].Legend := 'YES';
Series[1].Legend := 'NO';
SerLegBox := True;
SerLegBoxObj.Docked := TGFP_TOP;
End
end;
procedure TForm1.RadioButton2Click(Sender: TObject);
VAR
i: Integer;
s: String;
begin
// Line/Step
With ChartFX1 do begin
// Start from original chart
Import(CHART_CFXOLEFILE, 'original.chd');
Gallery := STEP;
// Init data. Each series is a separate line
OpenDataEx(COD_VALUES Or COD_REMOVE, 2, 10);
For i := 0 To 9 Do begin
ValueEx[0, i] := Random(50); // First line
ValueEx[1, i] := 50 + Random(50); // Second line
Str(i+1,s);
Legend[i] := 'Label' + s;
end;
CloseData(COD_VALUES);
// Hide one point
ValueEx[0, 5] := CHART_HIDDEN;
// Set color for each line
OpenDataEx(COD_COLORS, 2, 0);
Series[0].Color := CHART_PALETTECOLOR Or 44;
Series[1].Color := CHART_PALETTECOLOR Or 45;
CloseData(COD_COLORS);
// Series legend
Series[0].Legend := 'Yes';
Series[1].Legend := 'No';
SerLegBox := True;
SerLegBoxObj.Docked := TGFP_FLOAT;
End;
end;
procedure TForm1.RadioButton3Click(Sender: TObject);
VAR
dFrom,dTo:Double;
s:String;
i:Integer;
begin
// Gantt chart
With ChartFX1 Do Begin
// Start from original chart
Import(CHART_CFXOLEFILE, 'original.chd');
Gallery := GANTT;
RGB2DBk := RGB(255, 255, 255);
RGBBk := RGB(255, 255, 255);
AxesStyle := CAS_FLATFRAME;
// Y-Axis format
With Axis[AXIS_Y] Do Begin
Grid := True;
GridColor := RGB(192, 192, 192);
ResetScale;
Format := 'DMMM, yy';
Style := (Style Or AS_CENTERED Or AS_INTERLACED) And Not AS_SHOWENDS;
LabelAngle := 90;
ResetScale;
Step := 30; // Monthly
End;
// x-Axis format
With Axis[AXIS_X] do Begin
Grid := True;
GridColor := RGB(192, 192, 192);
Style := Style Or AS_CENTERED;
End;
// Set data and colors
// Starting point
OpenDataEx(COD_INIVALUES Or COD_REMOVE, 2, 8);
// Ending point point
OpenDataEx(COD_VALUES Or COD_REMOVE, 2, 8);
// Series legend
Series[0].Legend := 'Projected'; // White
Series[1].Legend := 'Actual'; // Black
SerLegBox := True;
// Bottom right
SerLegBoxObj.Docked := TGFP_BOTTOM;
SerLegBoxObj.BorderStyle := BBS_MONOLINE;
// Activities
ChartFX1.Title[CHART_TOPTIT] := 'My Project';
dFrom := StrToDate('01/01/98');
For i := 0 To 7 Do Begin
// Projected
dFrom := dFrom + Random(90);
dTo := dFrom + Random(90);
Series[0].YFrom[i] := dFrom;
Series[0].Yvalue[i] := dTo;
// Actual
Series[1].YFrom[i] := dFrom + Random(30)-15;
Series[1].Yvalue[i] := dTo + Random(30)-15;
// Label
Str(i+1,s);
Legend[i] := 'Activity ' + s;
end;
// Adjust Min and Max
With Axis[AXIS_Y] do begin
Min := StrToDate('01/01/98');
Max := StrToDate('12/31/98');
End;
CloseData(COD_INIVALUES);
CloseData(COD_VALUES);
End;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
// Save initial status
ChartFX1.Export(CHART_CFXOLEFILE, 'original.chd');
end;
procedure TForm1.RadioButton4Click(Sender: TObject);
VAR
d :Double;
i: Integer;
s:String;
begin
With ChartFX1 Do Begin
// Start from original chart
Import(CHART_CFXOLEFILE, 'original.chd');
Gallery := OPENHILOWCLOSE;
Volume := 20; // Thin bars
// Init data
OpenDataEx(COD_VALUES Or COD_REMOVE, 4, 30);
For i := 0 To 29 do Begin
d := 60 + Random(40);
ValueEx[OHLC_LOW, i] := d - Random(60);
ValueEx[OHLC_HIGH, i] := d;
ValueEx[OHLC_OPEN, i] := d - Random(20);
ValueEx[OHLC_CLOSE, i] := d - Random(20);
End;
CloseData(COD_VALUES);
// Format X-Axis
With Axis[AXIS_X] Do begin
Format := AF_DATE;
Min := Now+30;
Step := 7; // Weekly
FirstLabel := 1; // Show first day
End;
// Init colors
OpenDataEx(COD_COLORS, 3, 0);
Color[0] := RGB(0, 255, 0); // Went down !
Color[1] := RGB(255, 0, 0); // Went up !
Color[2] := RGB(0, 0, 0);
Color[3] := RGB(0, 0, 0);
CloseData(COD_COLORS);
End
end;
procedure TForm1.RadioButton5Click(Sender: TObject);
VAR
i: Integer;
begin
With ChartFX1 Do Begin
// Start from original chart
Import(CHART_CFXOLEFILE,'original.chd');
Gallery := BUBBLE;
OpenDataEx(COD_VALUES Or COD_REMOVE, 2, 6);
For i := 0 To 5 Do Begin
ValueEx[0, i] := 10 + Random(80); // Bubble position (Y)
ValueEx[1, i] := 60 + Random(40); // Bubble size
End;
CloseData(COD_VALUES);
End;
end;
procedure TForm1.RadioButton6Click(Sender: TObject);
VAR
i: Integer;
begin
// SCATTER (X/Y)
With ChartFX1 Do Begin
// Start from original chart
Import(CHART_CFXOLEFILE, 'original.chd');
Gallery := SCATTER;
MarkerSize := 5;
// Set X/Y data
OpenDataEx(COD_VALUES Or COD_REMOVE, 2, 10);
OpenDataEx(COD_XVALUES, 2, 10);
// Double scale
Series[0].YAxis := AXIS_Y;
Series[1].YAxis := AXIS_Y2;
// Init data
For i := 0 To 9 Do Begin
ValueEx[0, i] := Random(100);
XValueEx[0, i] := i * i;
ValueEx[1, i] := Random(100000);
XValueEx[1, i] := i * i + i;
End;
CloseData(COD_VALUES);
CloseData(COD_XVALUES);
// make second series a line
Series[0].Gallery := LINES;
// Format X-Axis
With Axis[AXIS_X] Do Begin
Step := 10;
MinorStep := 5;
Grid := True;
End;
// Format Primary Y-Axis
With Axis[AXIS_Y] Do Begin
Min := 0;
Max := 100;
End;
// Format Secondary Y-Axis
With Axis[AXIS_Y2] Do Begin
Min := 0;
Max := 100000;
End;
// Colors
OpenDataEx(COD_COLORS, 2, 0);
Series[0].Color := RGB(255, 0, 0);
Series[1].Color := RGB(0, 255, 0);
CloseData(COD_COLORS);
End;
end;
procedure TForm1.RadioButton7Click(Sender: TObject);
VAR
i: Integer;
s: String;
begin
// PIE Chart
With ChartFX1 Do Begin
// Start from original chart
Import(CHART_CFXOLEFILE, 'original.chd');
Gallery := PIE;
//show point labels
PointLabels := True;
// Initialize data for 2 pies
// Each value represents a slice
OpenDataEx(COD_VALUES Or COD_REMOVE, 2, 10);
For i := 0 To 9 Do Begin
ValueEx[0, i] := 20 + Random(100); // First PIE
ValueEx[1, i] := 40 + Random(100); // Second PIE
Str(i+1,s);
Legend[i] := 'Slice ' + s;
End;
CloseData(COD_VALUES);
//Separate the same slice in both the pies
SeparateSlice[2] := 25; // First pie 3rd slice
SeparateSlice[12] := 25; // Second pie
//Assign the series legend (PIE TITLES)
Series[0].Legend := 'Male';
Series[1].Legend := 'Female';
//Assign colors to the slices (10 slices per pie)
Palette := 'Spring';
OpenDataEx(COD_COLORS, 10, 0);
For i := 0 To 9 Do
Color[i] := CHART_PALETTECOLOR Or Random(40);
CloseData(COD_COLORS);
//to show the values legend box
LegendBox := True;
LegendBoxObj.Docked := TGFP_BOTTOM;
End;
end;
procedure TForm1.RadioButton8Click(Sender: TObject);
VAR
i: Integer;
s: String;
begin
// PYRAMID
With ChartFX1 Do Begin
// Start from original chart
Import(CHART_CFXOLEFILE, 'original.chd');
Gallery := PYRAMID;
// Init data. This is similar to PIE. Each series is a separate pyramid
OpenDataEx(COD_VALUES Or COD_REMOVE, 2, 5);
For i := 0 To 4 Do Begin
ValueEx[0, i] := 10 + Random(100); // First pyramid
ValueEx[1, i] := 10 + Random(100); // Second pyramid
Str(i+1,s);
Legend[i] := 'Slice ' + s;
End;
CloseData(COD_VALUES);
//Assign the series legend (PYRAMID TITLES)
Series[0].Legend := 'Male';
Series[1].Legend := 'Female';
End;
end;
procedure TForm1.RadioButton9Click(Sender: TObject);
VAR
i: Integer;
s: String;
begin
// radar chart
With ChartFX1 do Begin
// Start from original chart
Import(CHART_CFXOLEFILE, 'original.chd');
Gallery := RADAR;
MarkerShape := MK_NONE;
// Init Y-Axis (Radius)
With Axis[AXIS_Y] Do Begin
ResetScale;
Decimals := 0;
End;
// Init data. Each series is a line (color)
// The chart is drawn clockwise. The first point is at 12:00
// There are as many radius lines as points (60 in this case)
OpenDataEx(COD_VALUES Or COD_REMOVE, 2, 60);
For i := 0 To 59 Do Begin
ValueEx[0, i] := i; // Distance from center (first line)
ValueEx[1, i] := i * 2; // Distance from center (second line)
Str(i,s);
Legend[i] := s;
End;
CloseData(COD_VALUES);
// Format X axis (around)
With Axis[AXIS_X] Do Begin
Step := 5; // A radius line every 45 points
Grid := True;
FirstLabel := 1; // First label at 12:00
End;
End;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
ChartFX1.Chart3D := CheckBox1.Checked;
end;
procedure TForm1.CheckBox2Click(Sender: TObject);
begin
ChartFX1.Cluster := CheckBox1.Checked;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -