6
6ysnow
Unregistered / Unconfirmed
GUEST, unregistred user!
下文是一个完成的类单元:
unit UnMyChart;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons, TeEngine, Series, TeeProcs, Chart;
type
TMyGraph = class
private
AverageW,AverageH,NowPos:integer;
X1,X2,Y1,Y2,iTemp,Higth,Width : integer;
J_X,J_Y:integer;
SaveFlowGG :array of Integer;
iTotal :integer;
PosP: array of TPoint;
FFlowCount:integer ;
aCanvas: TCanvas;
public
constructor Create(FImage: TImage; X_count, Y_count: integer);
procedure SetFlowCount(Value:integer) ;
procedure DreawFlowChart() ;
procedure RealTimeLine();
end ;
implementation
{ TMyGraph }
constructor TMyGraph.Create(FImage: TImage; X_count, Y_count: integer);
var
K:Integer;
begin
J_X:=X_count;
J_Y:=Y_count;
setlength(SaveFlowGG,J_X);
setlength(PosP,J_X);
aCanvas:=FImage.Canvas;
// X1:=FImage.Left;
X1:=0;
X2:=FImage.Width+FImage.Left ;
Y1:=0;
Y2:=FImage.Top+FImage.Height ;
Width:=FImage.Width ;
Higth:=-FImage.Height; //这里为啥是负数,很奇怪的。
AverageW:= Width div J_X ;
AverageH:= Higth div J_Y ;
PosP[1].X:=AverageW;
for K:=0 to J_X-1 do
begin
PosP[K].X:=0;
PosP[K].Y:=0 ;
end ;
FImage.parent.doublebuffered := true; //防闪屏幕
end;
procedure TMyGraph.DreawFlowChart();
var
p:Array [0..3] of TPoint;
TheRect: TRect;
pTemp: TPoint;
k,G: integer;
begin
//X1:=65;X2:=480;Y1:=200;Y2:=40;
p[0]:=Point(X1,Y1); //(X1,Y1)
p[1]:=Point(X2,Y1); //(X2,Y1)
p[2]:=Point(X2,Y2); //(X2,Y2)
p[3]:=Point(X1,Y2); //(X1,Y2)
//画完矩形
aCanvas.Brush.Color:=clNone;
aCanvas.Pen.Color:=clNone;
aCanvas.Polygon(p);
//画横线
// J_Y:=10 ;
for k:= 0 to J_Y-1 do
begin
aCanvas.Pen.Color:= clLime;
pTemp.X:=X1;
pTemp.Y:=Y1-AverageH*(k+1);
aCanvas.PenPos:=pTemp;
aCanvas.LineTo(X2,pTemp.Y); //画横线
end;
//画竖线
for k:= 0 to J_X-1 do
begin
aCanvas.Pen.Color:= clLime;
pTemp.X:=X1+AverageW*(k+1);;
pTemp.Y:=Y1 ;
aCanvas.PenPos:=pTemp;
aCanvas.LineTo(pTemp.X,Y2); //画横线
end;
{
aCanvas.Pen.Color:= clred;
//再连线
for K:= 0 to J_X-2 do
begin
aCanvas.PenPos:=PosP[K];
aCanvas.LineTo(PosP[K+1].X,PosP[K+1].Y);
end; }
end;
procedure TMyGraph.RealTimeLine;
var
K,G:integer ;
begin
DreawFlowChart ;
aCanvas.Pen.Color:= clred;
//再连线
for K:= 0 to J_X-2 do
begin
//aCanvas.Pen.Style:=psSolid ;
for G:= 0 to k do
begin
// if PosP[k].X= 0 then exit;
aCanvas.PenPos:=PosP[G];
aCanvas.LineTo(PosP[G+1].X,PosP[G+1].Y);
end;
// PosP[G].X :=PosP[G+1].X;
// PosP[K+1].X :=PosP[K+1].X+AverageW;
end;
end;
procedure TMyGraph.SetFlowCount(Value: integer);
var
K:integer ;
begin
inc(iTotal);
if iTotal>J_X+1 then iTotal:=0;
FFlowCount:=Value ;
SaveFlowGG[iTotal]:=FFlowCount;
for K:=0 to J_X-1 do
begin
PosP[K].X:= X1+K*AverageW;
PosP[K].Y:=Y1-((SaveFlowGG[K] div 1000)*AverageH +round(((SaveFlowGG[K]mod 1000)*AverageH) div 1000)) ;
end ;
end;
end.
外部初始化:
FMyGraph:= TMyGraph.Create(Image1,20,10);
FMyGraph.DreawFlowChart();
timer画:
procedure TForm1.Timer1Timer(Sender: TObject);
var
i: integer;
begin
i:=Random(8000);
FMyGraph.SetFlowCount(i);
FMyGraph.RealTimeLine();
end;
流量曲线没有问题,就是存在一个小bug:
当所有点画完了后,下一轮又是从0开始变化。 我想一般应该是变化的点应该是最后一个,哪位有办法??
谢谢了
unit UnMyChart;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons, TeEngine, Series, TeeProcs, Chart;
type
TMyGraph = class
private
AverageW,AverageH,NowPos:integer;
X1,X2,Y1,Y2,iTemp,Higth,Width : integer;
J_X,J_Y:integer;
SaveFlowGG :array of Integer;
iTotal :integer;
PosP: array of TPoint;
FFlowCount:integer ;
aCanvas: TCanvas;
public
constructor Create(FImage: TImage; X_count, Y_count: integer);
procedure SetFlowCount(Value:integer) ;
procedure DreawFlowChart() ;
procedure RealTimeLine();
end ;
implementation
{ TMyGraph }
constructor TMyGraph.Create(FImage: TImage; X_count, Y_count: integer);
var
K:Integer;
begin
J_X:=X_count;
J_Y:=Y_count;
setlength(SaveFlowGG,J_X);
setlength(PosP,J_X);
aCanvas:=FImage.Canvas;
// X1:=FImage.Left;
X1:=0;
X2:=FImage.Width+FImage.Left ;
Y1:=0;
Y2:=FImage.Top+FImage.Height ;
Width:=FImage.Width ;
Higth:=-FImage.Height; //这里为啥是负数,很奇怪的。
AverageW:= Width div J_X ;
AverageH:= Higth div J_Y ;
PosP[1].X:=AverageW;
for K:=0 to J_X-1 do
begin
PosP[K].X:=0;
PosP[K].Y:=0 ;
end ;
FImage.parent.doublebuffered := true; //防闪屏幕
end;
procedure TMyGraph.DreawFlowChart();
var
p:Array [0..3] of TPoint;
TheRect: TRect;
pTemp: TPoint;
k,G: integer;
begin
//X1:=65;X2:=480;Y1:=200;Y2:=40;
p[0]:=Point(X1,Y1); //(X1,Y1)
p[1]:=Point(X2,Y1); //(X2,Y1)
p[2]:=Point(X2,Y2); //(X2,Y2)
p[3]:=Point(X1,Y2); //(X1,Y2)
//画完矩形
aCanvas.Brush.Color:=clNone;
aCanvas.Pen.Color:=clNone;
aCanvas.Polygon(p);
//画横线
// J_Y:=10 ;
for k:= 0 to J_Y-1 do
begin
aCanvas.Pen.Color:= clLime;
pTemp.X:=X1;
pTemp.Y:=Y1-AverageH*(k+1);
aCanvas.PenPos:=pTemp;
aCanvas.LineTo(X2,pTemp.Y); //画横线
end;
//画竖线
for k:= 0 to J_X-1 do
begin
aCanvas.Pen.Color:= clLime;
pTemp.X:=X1+AverageW*(k+1);;
pTemp.Y:=Y1 ;
aCanvas.PenPos:=pTemp;
aCanvas.LineTo(pTemp.X,Y2); //画横线
end;
{
aCanvas.Pen.Color:= clred;
//再连线
for K:= 0 to J_X-2 do
begin
aCanvas.PenPos:=PosP[K];
aCanvas.LineTo(PosP[K+1].X,PosP[K+1].Y);
end; }
end;
procedure TMyGraph.RealTimeLine;
var
K,G:integer ;
begin
DreawFlowChart ;
aCanvas.Pen.Color:= clred;
//再连线
for K:= 0 to J_X-2 do
begin
//aCanvas.Pen.Style:=psSolid ;
for G:= 0 to k do
begin
// if PosP[k].X= 0 then exit;
aCanvas.PenPos:=PosP[G];
aCanvas.LineTo(PosP[G+1].X,PosP[G+1].Y);
end;
// PosP[G].X :=PosP[G+1].X;
// PosP[K+1].X :=PosP[K+1].X+AverageW;
end;
end;
procedure TMyGraph.SetFlowCount(Value: integer);
var
K:integer ;
begin
inc(iTotal);
if iTotal>J_X+1 then iTotal:=0;
FFlowCount:=Value ;
SaveFlowGG[iTotal]:=FFlowCount;
for K:=0 to J_X-1 do
begin
PosP[K].X:= X1+K*AverageW;
PosP[K].Y:=Y1-((SaveFlowGG[K] div 1000)*AverageH +round(((SaveFlowGG[K]mod 1000)*AverageH) div 1000)) ;
end ;
end;
end.
外部初始化:
FMyGraph:= TMyGraph.Create(Image1,20,10);
FMyGraph.DreawFlowChart();
timer画:
procedure TForm1.Timer1Timer(Sender: TObject);
var
i: integer;
begin
i:=Random(8000);
FMyGraph.SetFlowCount(i);
FMyGraph.RealTimeLine();
end;
流量曲线没有问题,就是存在一个小bug:
当所有点画完了后,下一轮又是从0开始变化。 我想一般应该是变化的点应该是最后一个,哪位有办法??
谢谢了