Recent

Author Topic: TA Chart - format date  (Read 1043 times)

Nicole

  • Hero Member
  • *****
  • Posts: 972
TA Chart - format date
« on: September 15, 2022, 10:12:18 am »
I have a very basic chart.
The first date on the bottom-axes label should be "1.1.2017"
But I read "40900", i.e. the Julian format, which was the input.

in the format property I read, not sure, what this means and how it gets there
(in Chart.BottomAxes.Marks.Format)
%0:.9g

I changed it to
dd.mm.yyyy (which seemed no good idea)

because now I read in my chart on every date:
"dd.mm.yyyy" instead of the date

1)
What has there to be written to make the label show the date in "dd.mm.yyyyy"?

2)
Is this the right place for it at all?

3)
I add the data-points by code: "Series_Margin.AddXY(dat, margin);"
Would it be a better solution to add the marks by code as well?

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: TA Chart - format date
« Reply #1 on: September 15, 2022, 12:02:43 pm »
I have a very basic chart.
The first date on the bottom-axes label should be "1.1.2017"
But I read "40900", i.e. the Julian format, which was the input.
It should be the TDate number having its origin on Dec 30, 1899. But WriteLn(StrToDate('1.1.2017')) shows 42736 for me, rather than 40900. So maybe you have some typo here, or are doing something else...

in the format property I read, not sure, what this means and how it gets there
(in Chart.BottomAxes.Marks.Format)
%0:.9g
This is a format mask used by the SysUtils.Format() function (using %0:.2f, for example would label the axis with two decimal places; read the docs about what the "0" means here). "dd.mm.yyyy", however, is for the FormatDateTime function which uses a different mask type. So, sorry, this property cannot be used to create a date/time format.

[...] to make the label show the date in "dd.mm.yyyyy"?
Assuming that the date is on the X axis of the chart, add a TDateTimeIntervalChartSource to the form and link it to the Chart.BottomAxis.Marks.Source and set Chart.BottomAxis.Marks.Style to smsLabel. This way the DateTimeIntervalChartSource takes control over labelling and seeks for "nice" labels, even when the chart is zoomed.

Unfortunately the DateTimeIntervalChartSource sometimes produces unwanted results. In this case, it is better when you use the x values of the series directly. I assume that you added the data points to the series as "AddXY(date, y)". Add the date string as label ("AddXY(date, y, DateToStr(date))"), and set Chart.BottomAxis.Marks.Source to LineSeries.ListSource and Chart.BottomAxis.Marks.Style to smsLabel (requires unit TAChartUtils). To prevent overlapping labels, either rotate the axis marks (Chart.BottomAxis.Marks.LabelFont.Orientation = 900) and/or adjust the Increment settings of the axis (Chart.BottomAxis.Increments.MaxLength = 150, Chart.BottomAxis.Increments.MinLength := 80). This will place labels only at the positions of the data points - which will look strange when the data points are irregularly spaced. An alternative is to add a TListChartSource, link it to the axis (as I described for the DateTimeIntervalChartSource) and manually add the label coordinates and texts manually (I posted this recently with a code sample, please search the forum).

Another option would be to provide a handler for the OnGetMarkText event of the axis in which you can format the mark text in any way:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Chart1AxisList1GetMarkText(Sender: TObject; var AText: String;
  2.   AMark: Double);
  3. begin
  4.   AText := DateToStr(AMark);
  5. end;

Nicole

  • Hero Member
  • *****
  • Posts: 972
[soled] Re: TA Chart - format date
« Reply #2 on: September 15, 2022, 02:48:20 pm »
Thank you so much for the verbose answer!

I did as explained, and my dd.mm.yy data rotate (thank you for the hint) around their center nicely now. It looks ok, but if you say "produces unwanted results", this may change in some cases.

May the thing make problems, if complexity increases?

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: [soled] Re: TA Chart - format date
« Reply #3 on: September 15, 2022, 03:21:28 pm »
I did as explained, and my dd.mm.yy data rotate (thank you for the hint) around their center nicely now. It looks ok, but if you say "produces unwanted results", this may change in some cases.

May the thing make problems, if complexity increases?
The "thing" is the DateTimeIntervalChartSource? "Unwanted results" - I mean: "not what user expects". You said above that "The first date on the bottom-axes label should be 1.1.2017". The DateTimeIntervalChartSource does not do this necessarily. Depending on the size of the chart, the real axis limits and interval values, and the Params settings, it may place the 1st label at Dec 28, 2016, and the next one at Jan 5, 2017 or whatever...

Nicole

  • Hero Member
  • *****
  • Posts: 972
Re: TA Chart - format date
« Reply #4 on: September 16, 2022, 11:45:19 am »
ah, yes, I see. This I found strange in the meanwhile, however in this basic chart I can live with it because my Richmemo gives me the data as well.

btw.: Do you know what TeeChart means with by a "Big Candle"?
(if no and if you are interested, I will generate a screenshot)
This allows to zoom out one single bar of a displayed chart and to get it values into extra labels.

This is the way I helped myself in case of such cases of too large intervals.
Not sure, if TAChart support it.

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: TA Chart - format date
« Reply #5 on: September 16, 2022, 11:01:25 pm »
Do you know what TeeChart means with by a "Big Candle"?
No
(if no and if you are interested, I will generate a screenshot)
Please

 

TinyPortal © 2005-2018