Recent

Author Topic: [SOLVED] How to use NiceSteps in a Βottom Axis  (Read 3769 times)

donnie

  • Jr. Member
  • **
  • Posts: 72
[SOLVED] How to use NiceSteps in a Βottom Axis
« on: January 30, 2017, 12:55:19 pm »
Hi there,
I have a Chart, in which bottom axis is connected with a DateTimeIntervalChartSource. (Chart->BottomAxis->Marks->Source->DateTimeIntervalChartSource and Style->smsLabel).
As to the topic How to Use nice Stps to LeftAxis(http://forum.lazarus.freepascal.org/index.php/topic,34219.0.html) I have made some values in order to have marks to let's say every 5 days. The problem is that if the date range is wide enough it is 'confused'(maybe the mixlength and maxlength ). I need a general solution e.g. per Day, Week, Month. The field DateTimeIntervalChartSource -> Steps is refered to the zoom factor.
I was wondering that if the chart itself can understand that date range to the zoom factor, maybe that can happen as a variable to nice steps.
Let's say that we have a chart that it's bottom axis is from 01/10/2016 to 31/12/2016. I am trying to find that parameter that:
If i choose it in days I want to have marks at 01/10,02/10, 03/10...29/12, 30/12, 31/12.
If i choose it in weeks I want to have marks at 01/10,08/10, 15/10...16/12, 23/12, 30/12.
If i choose it in months I want to have marks at 01/10, 01/11, 01/12.
« Last Edit: February 02, 2017, 11:27:53 am by donnie »

wp

  • Hero Member
  • *****
  • Posts: 11906
Re: How to use NiceSteps in a Βottom Axis
« Reply #1 on: January 30, 2017, 04:43:31 pm »
I was playing a bit with the DateTimeIntervalChartSource in the same way I did in the LeftAxis thread that you cited. But I did not get an acceptable solution.

Axis labelling is very complex and depends on many factors, and data/time axis is even more complex because of the irregular lengths of months (28/29/30/31 days) and years (365/366 days).

If you have specific labeling requirements then it's best to replace the DateTimeIntervalchartSource by a standard ListChartSource in which you store all the labels to be used.

The attached code populates a ListChartSource this way: If the "autodetect" checkbox is off then you select the date/time units by means of the combobox; if it is on the program calculates the length of the displayed axis range and selects an appropriate unit. If labels are too close and overlap you can increase the SpinEdit to skip a given number of labels.

Since this is code outside the TAChart library you can modify it as you like, for example to adjust the format strings.

donnie

  • Jr. Member
  • **
  • Posts: 72
Re: How to use NiceSteps in a Βottom Axis
« Reply #2 on: January 31, 2017, 02:21:20 pm »
Nice approach wp!
This demo must be added to the TAChart samples for sure!
It is much better with ListChartSource indeed. The autodetect confused me a bit as it takes consider of the spinedit value and split it to the maximum possible unit of the bottom axis.
Thanks once again.

 

TinyPortal © 2005-2018