Add Time on X Axis TDBAdvGrid

Hello I'm try tu use a Access DB with



I need to have on X-Axis the real time value, with format "hours:minutes:second:millisecond"

I assigne
XAxis.MajorUnitTimeFormat := 'hh:nn:ss';
XAxis.DateTimeFormat := 'hh:nn:ss';

But on X-Axis appear "27/04/2021 10:52:22" instead "10:52:22" ?
Who I can add millisecond?
Why the space from a record with distance 1 second is the same space from two record with distance 13 second?

Using this code to set the panes:
procedure TForm1.GraphAddPagx(NumPan : word);
var
I : word;
begin

DBGraph.BeginUpdate;
with DBGraph.Panes[NumPan] do
begin
Series.Clear;

//Datasource property of Chart
DataSource := DSTab1;

XAxis.Position := xBottom;
XAxis.UnitType := utMinute;
XAxis.Size     := 150;

Range.StartDate := Now; 

YAxis.Size := 100;
BorderColor := clLime;
XGrid.Visible := true;
XGrid.MajorDistance := 4;
XGrid.MinorDistance := 2;
XGrid.MajorLineColor := clGray;
XGrid.MinorLineColor := clsilver;


Margin.RightMargin := 30;
Bands.Distance         := 2;
Bands.GradientSteps    := 100;
Bands.PrimaryColor     := RGB(229,244,244);
Bands.PrimaryColorTo   := RGB(229,244,244);
Bands.SecondaryColor   := clWhite;
Bands.SecondaryColorTo := clWhite;
Bands.SerieIndex       := 0;
Bands.Visible          := True;



Series.Add;
with Series[0] do
begin
  LineColor := clBlack;
  FieldNameValue := 'Val1';
  FieldNameXAxis := 'Time';
  LegendText := 'valore1';
  XAxis.Visible  := True;
end;

Series.Add;
with Series[1] do
begin
  LineColor      := clMaroon;
  FieldNameValue := 'Val2';
  FieldNameXAxis := 'Time';
  LegendText     := 'valore2';
  XAxis.Visible  := False;
end;

Series.Add;
with Series[2] do
begin
  LineColor      := clGreen;
  FieldNameValue := 'Val3';
  FieldNameXAxis := 'Time';
  LegendText     := 'valore3';
  XAxis.Visible  := False;
end;

Series.Add;
with Series[3] do
begin
  LineColor      := clOlive;
  FieldNameValue := 'Val4';
  FieldNameXAxis := 'Time';
  LegendText     := 'valore3';
  XAxis.Visible  := False;
end;

Series.Add;
with Series[4] do
begin
  LineColor      := clNavy;
  FieldNameValue := 'Val5';
  FieldNameXAxis := 'Time';
  LegendText     := 'valore3';
  XAxis.Visible  := False;
end;

Series.Add;
with Series[5] do
begin
  LineColor      := clPurple;
  FieldNameValue := 'Val6';
  FieldNameXAxis := 'Time';
  LegendText     := 'valore3';
  XAxis.Visible  := False;
end;

Series.Add;
with Series[6] do
begin
  LineColor      := clTeal;
  FieldNameValue := 'Val7';
  FieldNameXAxis := 'Time';
  LegendText     := 'valore3';
  XAxis.Visible  := False;
end;

Series.Add;
with Series[7] do
begin
  LineColor      := clBlue;
  FieldNameValue := 'Val8';
  FieldNameXAxis := 'Time';
  LegendText     := 'valore3';
  XAxis.Visible  := False;
end;


for I := 0 to Series.Count - 1 do
begin
  with Series[I] do
  begin
    AutoRange := arEnabled;
    ChartType := ctXYLine;
    LineWidth := 2;
    YAxis.MajorUnit := 100;
    YAxis.MajorUnit := 0;
    ChartType := ctLine;
    AutoRange := arDisabled;
    XAxis.TextBottom.Angle := 45;
    XAxis.AutoUnits := false;
    XAxis.MajorUnitTimeFormat := 'hh:nn:ss';
    XAxis.DateTimeFormat := 'hh:nn:ss';


  end;
end;

end;
DBGraph.EndUpdate;

end;

Hi,

The text on the X-Axis is overriden by FieldNameXAxis := 'Time'; please remove this property to configure your own time x-axis.

1-
Thank the information seem work good :slight_smile:

2-
To add millisecond I have changed
XAxis.UnitType := utSecond; --> XAxis.UnitType := utMilliSecond;
and set to
XAxis.MajorUnitTimeFormat := 'hh:nn:ss:zzz';
XAxis.DateTimeFormat := 'hh:nn:ss:zzz';

is ok?

3-
when I add the 1st record is all ok

but when add the 2nd change also the 1st record displayed, what can be the problem?

best regards

This is because there are auto-units for the X-Axis which are auto-calculated. If you wish to add the real values corresponding with the points, you need to use ctXYLine chart type instead. This will add an additional X-Axis which will represent the values. You can also turn on and off this x-axis with the following code:

Series.Add;
with Series[1] do
begin
  LineColor      := clMaroon;
  FieldNameValue := 'Val2';
  FieldNameXAxis := 'Time';
  LegendText     := 'valore2';
  XAxis.Visible  := False;
  ChartType := ctXYLine;
  XAxis.XValues := True;
end;

Ok now the x label seem work,

but now I lost the data formatting 'hh:mm:ss:zzz'

and the graph is not real
the 1st part is 1 second, the next part is 7 second, but the space on graph is exactly the same,

Hi,

The issue is that the DB version does not add XY points, only normal points, that is the reason why the value is not correctly placed. To workaround this you'll need to manually step through the dataset and then add points to the series with AddSingleXYPoint where you specify the timestamp.