Recent

Author Topic: [SOLVED] dateTime values into datapoints editor  (Read 3086 times)

wittbo

  • Full Member
  • ***
  • Posts: 150
[SOLVED] dateTime values into datapoints editor
« on: January 03, 2018, 04:18:23 pm »
I'm just experimenting with the TAChart components. I need a DateTime value based X-Axis, for quick checking I would like to use the datapoints editor of the ListChartSource component. Is it possible to enter datetime values directly into the X column of the editor (actually I don't have success, for example I entered '01/01/2018', but the result was 0) or does is only accept numeric values?
Thanks for help.
« Last Edit: January 04, 2018, 01:10:59 pm by wittbo »
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: dateTime values into datapoints editor
« Reply #1 on: January 03, 2018, 06:44:54 pm »
The datapoints editor only accepts numbers in the X and Y columns. Of course, TDate, TTime and TDateTime are numbers internally. The number value of Jan 1 2018 for example is 43101. So, if you want to construct X date values in 1-day intervals starting at Jan 1, you enter the numbers 43101, 43102, 43103, etc. in the X column.

In r56940 I modified the ListChartSource to accept also date/time values in the X and Y columns. You must change to  Lazarus trunk to get this feature. Or you must patch your local Lazarus version yourself with these two changes:

  • Open unit tachartutils.pas (from (lazarus)/components/tachart) and add a function which, of course, must be declared also in the interface part of the unit:
Code: Pascal  [Select][+][-]
  1. function StrToFloatOrDateTimeDef(const AStr: String): Double;
  2. begin
  3.   if
  4.     not TryStrToFloat(AStr, Result, DefSeparatorSettings) and
  5.     not TryStrToFloat(AStr, Result) and
  6.     not TryStrToDateTime(AStr, Result)
  7.   then
  8.     Result := 0.0;
  9. end;
  • Then open unit tasources.pas and find procedure TListChartSourceStrings.Parse. Replace each one of the three calls to StrToFloatDefSep by this new function, StrToFloatOrDateTimeDef.
Nevertheless, using the datapoints editor is not really recommended. Better to write a few lines of code to add the data points.

wittbo

  • Full Member
  • ***
  • Posts: 150
Re: dateTime values into datapoints editor
« Reply #2 on: January 04, 2018, 01:09:17 pm »
Thanks a lot for your answer. It was a good help.
Of course it will be better to write code in practice. But the datapoints editor is quite good for experimenting during design time with the effects of the hundreds ( :) ) of TChart Parameters, which are rather complex for TAChart newbies like me.
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: [SOLVED] dateTime values into datapoints editor
« Reply #3 on: January 04, 2018, 02:36:46 pm »
Of course. But usually, your precise data are not needed at all just to play with parameters and to see what they change. It is much easier to use a TRandomChartsource for the design phase and replace it later by the chart source with the real data. I once described this strategy in a tutorial, http://wiki.lazarus.freepascal.org/TAChart_Tutorial:_Stacked_BarSeries#Designing_the_chart_with_random_data is section on the design phase.

 

TinyPortal © 2005-2018