-1

Presently, i got a DBChart with multiple line series on it. I put the date-time of each record on the x-axes.

Now, what i need is to change the date-time for a runtime. So basically, the first recorded date-time would represent 0.0hrs.

Here some example of what i mean :

  1. 2017-01-05 08:00:00 = Point should show 0.0hrs on axes X
  2. 2017-01-05 08:30:00 = Point should show 0.5hrs on axes X
  3. 2017-01-05 09:00:00 = Point should show 1.0hrs on axes X
  4. 2017-01-05 09:30:00 = Point should show 1.5hrs on axes X
  5. 2017-01-05 10:00:00 = Point should show 2.0hrs on axes X
  6. 2017-01-05 10:30:00 = Point should show 2.5hrs on axes X
  7. ETC............

Basically, the chart show what happen between the time i start and stop recording my value in the database. Its more important to know how must time has pass since the beginning of the recording.

So, is there a function or some other way in DBChart that can help me do that?

Thanks for your help

Carl
  • 23
  • 3

1 Answers1

0

You can use OnGetAxisLabel event to calculate the difference and show it. Ie:

var startDate: TDateTime;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Series1.FillSampleValues(10);

  startDate:=StrToDateTime('08/02/2017 10:00:00');

  Series1.XValue[0]:=startDate;
  for i:=1 to Series1.Count-1 do
     Series1.XValue[i]:=Series1.XValue[i-1]+Round(random*10)*DateTimeStep[dtTenMinutes];
end;

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
  ValueIndex: Integer; var LabelText: string);
var tmpDate: TDateTime;
begin
  if (Sender = Chart1.Axes.Bottom) then
  begin
    tmpDate:=StrToDateTime(LabelText);
    tmpDate:=tmpDate-startDate;
    LabelText:=FormatDateTime('hh:mm:ss', tmpDate);
  end;
end;
Yeray
  • 5,009
  • 1
  • 13
  • 25
  • Thanks for the answers, it was what i was looking for. I just had to modify it a little since the chart could record on multiple days so the formatdatetime would not work for me. Now, is it possible to show the first record at 0.0hrs because right now, the bottom chart will show me -0.5, 0.5, 1.5, 2.5 etc. I would prefer that it show 0hrs, 1 hrs, 2 hrs etc. So, basically, is it possible to tell the chart which record i should use for marking the bottom axes. Right now, its doing it automatically. – Carl Feb 08 '17 at 15:10