Recent

Author Topic: Set x axis datetime to display  (Read 3417 times)

dnota

  • New Member
  • *
  • Posts: 13
Set x axis datetime to display
« on: October 06, 2015, 12:47:59 pm »
Hi all,
I'm having some problems with tacharts.
I have data every 15 minutes at an interval of 7 days, you can see an example at the image.
I need to set vertical grid lines and x axis label every day at 00:00, can anyone bring me some light to this problem?

P.D: Sorry for my writing but I'm not English

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Set x axis datetime to display
« Reply #1 on: October 06, 2015, 12:57:46 pm »
Is it required that you can zoom into the chart and the labels adjust automatically? This would create some conflict with your requirement to have labels at 0:00 only.

dnota

  • New Member
  • *
  • Posts: 13
Re: Set x axis datetime to display
« Reply #2 on: October 06, 2015, 01:16:20 pm »
Well, axis labels are not importants, the important thing here is the vertical grid line, this is needed at 00:00 and stay at 00:00 when you zoom.

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Set x axis datetime to display
« Reply #3 on: October 06, 2015, 03:48:17 pm »
The DateTimeIntervalChartSource which you seem to be using lacks some control of exact placement of labels. I am working on it, but do not yet have a satisfactory solution.

What you can do is to add a TListChartSource to your form and populate it with the values where you want to have a label (and a grid line - they are at the same positions). In the this routine you also add the text which will be displayed. You have to assign this ChartSource to the Source property of the bottom axis Marks, and you have to set the Marks' Style to smsLabel to see the assigned texts:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ConstructXLabels;
  2. var
  3.   ex: TDoubleRect;
  4.   dt: TDateTime;
  5. begin
  6.   ListChartSource1.Clear;
  7.   ex := Chart1.CurrentExtent;
  8.   dt := ex.a.x;
  9.   while dt <= ex.b.x+1 do begin
  10.     ListChartSource1.Add(trunc(dt), trunc(dt), FormatDateTime('dd"/"mm"/"yyyy"', trunc(dt)));
  11.     dt := dt + 1;
  12.   end;
  13.   Chart1.BottomAxis.Marks.Source := ListChartSource1;
  14.   Chart1.BottomAxis.Marks.Style := smsLabel;
  15. end;
This code creates labels at midnight and assigns to them the strings for the coming day. Call this when the chart is ready, e.g. in its OnExtentChanging event.

If you want also intermediate ticks you can add a minor chart axis to the bottomaxis where you, for example, draw a tickmark every 3 hours, i.e. set the Intervals.Count of the minor axis to 24/3-1 = 7.

See the attached demo.
« Last Edit: October 06, 2015, 03:49:55 pm by wp »

dnota

  • New Member
  • *
  • Posts: 13
Re: Set x axis datetime to display
« Reply #4 on: October 07, 2015, 08:21:53 am »
Great, thank you very much.

 

TinyPortal © 2005-2018