(26-05-2020, Saat: 17:10)mrmarman Adlı Kullanıcıdan Alıntı: DBChart nesnenizi manuel oluşturarak deneyin. Bir şeyleri deneme yanılma ile yanlış ayarlamış olabilirsiniz.
her eklenen veri için aşağıdaki gibi bir akış olacak.
procedure TForm1.Timer1Timer(Sender: TObject);
var
aValue : Integer;
begin
aValue := Random( 200 );
AddRecord( DBChart1.SeriesList[0], aValue );
FDQuery1.Refresh;
FDQuery1.Last;
DBChart1.RefreshData;
LimitAxis( DBChart1.SeriesList[0] );
end;
procedure TForm1.ButtonRecordTimerClick(Sender: TObject);
var
i : Integer;
aValue : Integer;
begin
// -------------------------------------------------------------------------- //
// DBChart 1
// -------------------------------------------------------------------------- //
With DBChart1 do
begin
for i := 0 to SeriesCount -1 do Series[i].Free;
ClearChart;
AutoSize := False;
View3D := False;
Legend.Visible := False;
Align := alNone;
AxisBehind := True; // axis ref.lines must behinde the chart
With Title do begin
Visible := True;
Text.Clear;
Text.Add( 'Örnek Grafik' );
Text.Add( '' );
Alignment := TAlignment.taCenter;
Font.Style := [fsBold];
Font.Size := 12;
Font.Name := 'Tahoma';
Font.Color := clMaroon;
Bevel := bvRaised;
end;
With LeftAxis do begin
Visible := True;
AutomaticMaximum := False;
SetMinMax( -5, 250 );
Increment := 1.0;
Grid.Visible := False;
With Title do begin
Caption :='Değerler';
Alignment := TAlignment.taCenter;
Font.Style := [fsBold];
Font.Size := 8;
Font.Name := 'Arial';
Font.Color := clBlack;
Bevel := bvLowered;
Brush.Color := clYellow;
Brush.Style := bsSolid;
Transparent := False;
Transparency := 25;
ClipText := True;
end;
end;
With BottomAxis do begin
Visible := True;
Texts.Angle := 90;
Texts.Size := 20;
Ticks.Color := clRed;
Automatic := True;
MinorTicks.Visible := True;
MinimumOffset := 0;
MaximumOffset := 0;
end;
end;
with DBChart1.AddSeries(TFastLineSeries) as TFastLineSeries do // idx: 0
begin
Legend.Visible := False;
XValues.Order := loNone;
TreatNulls := tnDontPaint;
SeriesColor := clBlue;
Pen.Color := clBlack;
Pen.Style := psSolid;
Pen.Width := 2;
Marks.Visible := true;
Marks.Style := smsValue;
VertAxis := aLeftAxis;
HorizAxis := aBottomAxis;
end; // with
DBChart1.SeriesList[0].DataSource := qrygrafik;
DBChart1.SeriesList[0].XValues.ValueSource := 'tarih';
DBChart1.SeriesList[0].XValues.DateTime := true;
DBChart1.SeriesList[0].YValues.ValueSource := 'deger';
LimitAxis( DBChart1.SeriesList[0] );
end;
@
mrmarman hocam,
son durum bu şekilde.
Kodların son durumu da bu :
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Data.DB, MemDS, DBAccess,
Uni, UniProvider, MySQLUniProvider, Vcl.ExtCtrls, Vcl.Grids, Vcl.DBGrids,
VCLTee.TeEngine, VCLTee.TeeFunci, VCLTee.Series, VCLTee.TeeProcs,
VCLTee.Chart, VCLTee.DBChart, Math;
type
TForm1 = class(TForm)
unicon_mysql: TUniConnection;
MySQLUniProvider1: TMySQLUniProvider;
qrygrafik: TUniQuery;
srcgrafik: TDataSource;
DBGrid1: TDBGrid;
DBChart1: TDBChart;
Button2: TButton;
Timer1: TTimer;
Button3: TButton;
procedure LimitAxis( aChartSeries: TChartSeries );
procedure DBChart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
ValueIndex: Integer; var LabelText: string);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.LimitAxis( aChartSeries: TChartSeries );
const
iVisibleValuesCount = 80;
var
i, iMin, iMax : Integer;
begin
With aChartSeries do
begin
iMin := Count - iVisibleValuesCount;
iMax := pred( Count );
if iMin < 0 then iMin := 0;
// Hide old/previous visible marks
// ( to prevent show marks outside the chart canvas )
for i := iMin downto iMin - 20 do begin
if iMin > 0
then Marks[ i ].Visible := False;
end;
ParentChart.BottomAxis.SetMinMax( aChartSeries.XValues[iMin] , aChartSeries.XValues[iMax]); // this is the magic
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
aValue : Integer;
begin
aValue := Random( 200 );
qrygrafik.Insert;
qrygrafik.FieldByName('deger').value := avalue;
qrygrafik.FieldByName('tarih').value := date + time;
qrygrafik.post;
qrygrafik.Refresh;
qrygrafik.Last;
DBChart1.RefreshData;
LimitAxis( DBChart1.SeriesList[0] );
application.ProcessMessages;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i : Integer;
aValue : Integer;
begin
// -------------------------------------------------------------------------- //
// DBChart 1
// -------------------------------------------------------------------------- //
With DBChart1 do
begin
for i := 0 to SeriesCount -1 do Series[i].Free;
ClearChart;
AutoSize := False;
View3D := False;
Legend.Visible := False;
Align := alNone;
AxisBehind := True; // axis ref.lines must behinde the chart
With Title do begin
Visible := True;
Text.Clear;
Text.Add( 'Örnek Grafik' );
Text.Add( '' );
Alignment := TAlignment.taCenter;
Font.Style := [fsBold];
Font.Size := 12;
Font.Name := 'Tahoma';
Font.Color := clMaroon;
Bevel := bvRaised;
end;
With LeftAxis do begin
Visible := True;
AutomaticMaximum := False;
SetMinMax( -5, 250 );
Increment := 1.0;
Grid.Visible := False;
With Title do begin
Caption :='Değerler';
// Alignment := TAlignment.taCenter;
Font.Style := [fsBold];
Font.Size := 8;
Font.Name := 'Arial';
Font.Color := clBlack;
Bevel := bvLowered;
Brush.Color := clYellow;
Brush.Style := bsSolid;
Transparent := False;
Transparency := 25;
// ClipText := True;
end;
end;
With BottomAxis do begin
Visible := True;
// Texts.Angle := 90;
// Texts.Size := 20;
Ticks.Color := clRed;
Automatic := True;
MinorTicks.Visible := True;
MinimumOffset := 0;
MaximumOffset := 0;
end;
end;
with DBChart1.AddSeries(TFastLineSeries) as TFastLineSeries do // idx: 0
begin
// Legend.Visible := False;
XValues.Order := loNone;
TreatNulls := tnDontPaint;
SeriesColor := clBlue;
Pen.Color := clBlack;
Pen.Style := psSolid;
Pen.Width := 2;
Marks.Visible := true;
Marks.Style := smsValue;
VertAxis := aLeftAxis;
HorizAxis := aBottomAxis;
end; // with
DBChart1.SeriesList[0].DataSource := qrygrafik;
DBChart1.SeriesList[0].XValues.ValueSource := 'tarih';
DBChart1.SeriesList[0].XValues.DateTime := true;
DBChart1.SeriesList[0].YValues.ValueSource := 'deger';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
timer1.Enabled := true;
end;
procedure TForm1.DBChart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
ValueIndex: Integer; var LabelText: string);
var
aDate: TDateTime;
begin
if (Sender = DBChart1.Axes.Bottom) then
begin
aDate := StrToDateTime(LabelText);
LabelText := FormatDateTime('dd.mm.yyyy', aDate);
end;
end;
end.
DBChartı sildim. Sizin kodu ekledim. Yinede ben de kaydırma işlemi yapmıyor bir türlü. Bu kadar uğraşmamıştım hiç.
Yazılımcı, kahveyi koda çeviren bir organizmadır.