Recent

Author Topic: DateTime for TChart Bottom Axis  (Read 37781 times)

Tom

  • Newbie
  • Posts: 6
DateTime for TChart Bottom Axis
« on: May 06, 2010, 12:54:12 pm »
I want to display float values versus DateTime using TChart. Delphi has the property XValues.DateTime for the ChartSeries and setting it to true gives the desired effect.

I found out, that the label text for the Axis gets created in "tatypes.pas" -> MarkToText() and I can simply edit the implementation to display DateTime values.

However, this affects all axes, so I would like to find a proper way to implement such a datetime axis.

I would like to derive a new class from TChart that allows me to override DrawAxis() in order to carefully change the labelling of one axis only to display DateTime values.

I think I need to add a new property to TChartAxis like "DateTime" : Boolean and then check for this when I generate the text.

My problem is, I can only make these changes by either copying the TAChart component into my project folder or directly editing it in the lazarus/components/tachart folder.

Is there a way to derive from TChart and implement the changes this way? All the properties and members are either private or protected, so I cannot override them in another unit...

Best regards,
Tom

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: DateTime for TChart Bottom Axis
« Reply #1 on: May 07, 2010, 08:45:21 am »
If you use the SVN version, Date/Time axis values are already possible.
Look at components/tachart/demo/axis/axisdemo, "Customized marks" page.

Tom

  • Newbie
  • Posts: 6
Re: DateTime for TChart Bottom Axis
« Reply #2 on: May 09, 2010, 09:54:34 pm »
Ah, ok - I'll give it a try... Thanks!

pacific2

  • New Member
  • *
  • Posts: 17
Re: DateTime for TChart Bottom Axis
« Reply #3 on: July 31, 2010, 12:52:51 pm »
Dear all
Is there something new in this topic ?

I try to use Tachart with time series (in chartlineseries) and I need to have a bottom axis as (dd/mm/yyy) for all points of the serie. For the moment I did not find solution.

Thanks in advance


Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: DateTime for TChart Bottom Axis
« Reply #4 on: July 31, 2010, 06:07:08 pm »
Did you look at components/tachart/demo/axis/axisdemo, "Customized marks" page?

pacific2

  • New Member
  • *
  • Posts: 17
Re: DateTime for TChart Bottom Axis
« Reply #5 on: July 31, 2010, 09:37:27 pm »
I did, but this demo use the source property of the ChartCustomerBarSeries objet in order to enter manualy the datapoint as a list, as below:
1|18000|?|January
2|35000|?|February
3|31000|?|March
4|26000|?|April
5|37000|?|May
6|22000|?|June

I would like to enter directly the data set (in lineseries with addxy) and not manualy as in the demo.

I tryed tu use the delphi teechart operating mode but this do not work. For exemple to set the date format:
s1.XValues.DateTime := True;
Chart3.BottomAxis.DateTimeFormat:='dd/mm/yyyy';

by the way I use the Typhon code version of lazarus. But I think this does not matter

regards

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: DateTime for TChart Bottom Axis
« Reply #6 on: August 01, 2010, 01:34:30 am »
The key here is that you can assign arbitrary source to axis marks.
After that, you can set Marks.Style = smsLabel and use

Code: [Select]
LineSeries.AddXY(x, y, FormatDateTime('dd/mm/yyyy', x));
Or, alternatively, assign OnMarkToText event handler to format
labels on the fly, which may be slightly more efficient if you have very long series.
« Last Edit: August 01, 2010, 01:37:27 am by Ask »

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: DateTime for TChart Bottom Axis
« Reply #7 on: August 01, 2010, 05:18:03 am »
Also, since r26951 you can use TDateTimeIntervalChartSource
for simplified datetime formatting.
See "Date and Time" page in the axisdemo.

pacific2

  • New Member
  • *
  • Posts: 17
Re: DateTime for TChart Bottom Axis
« Reply #8 on: August 01, 2010, 11:05:57 am »
Thanks

To avoid mistake, I started a new project with a basic chart. I added the folowing code:

chart1lineseries1.AddXY(2, 2, FormatDateTime('dd/mm/yyyy', strtodate('01/01/2010')),1);
  chart1lineseries1.AddXY(3, 3, FormatDateTime('dd/mm/yyyy', strtodate('10/01/2010')),1);         

Then I put the Marks style to smslabel (through the object inspector). The programme compile and run with a line on the chart  but no date on the axis. The bottom axis is empty. I olso tryed to put smslabel in the code (chart1.BottomAxis.Marks.Style:=smslabel; ) but this does not compile because the word smslabel is not recognized)

I installed my code typhon lazarus version few weeks ago but mybe the tachart package is not up to date. Do yo know the link to the latest version ? I had a look on sourceforge but the version date is very old (2006). !

thanks again

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: DateTime for TChart Bottom Axis
« Reply #9 on: August 01, 2010, 11:23:24 am »
Quote
Then I put the Marks style to smslabel (through the object inspector). The programme compile and run with a line on the chart  but no date on the axis. The bottom axis is empty.

Did you set Marks.Source property?

Quote
I also tried to put smsLabel in the code (chart1.BottomAxis.Marks.Style:=smslabel; ) but this does not compile because the word smsLabel is not recognized)

You have to add TAChartUtils unit to uses clause.

Quote
I installed my code typhon lazarus version few weeks ago but mybe the tachart package is not up to date.

Sourceforge package is very outdated, do not use it.
TAChart is a part of Lazarus for a few years already.
So, TAChart version is equal to the Lazarus version.
You can look at the Lazarus version in Help/About Lazarus dialog.
If you want to get latest changes, use either SVN or daily snapshots
(see links on the left panel of the forum).

pacific2

  • New Member
  • *
  • Posts: 17
Re: DateTime for TChart Bottom Axis
« Reply #10 on: August 01, 2010, 11:49:11 am »
The marks.source property is empty in the object inspector. How can I set it ?

ok for TAChartUtils chart1.BottomAxis.Marks.Style:=smslabel; compile now.


Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: DateTime for TChart Bottom Axis
« Reply #11 on: August 01, 2010, 12:02:45 pm »
Quote
The marks.source property is empty in the object inspector. How can I set it ?

Did you look at components/tachart/demo/axis/axisdemo, "Customized marks" page?

In particular, note lcsMarks component.

Alternatively, you may assign
Code: [Select]
Marks.Source := LineSeries1.Source, but that can be done at run-time only.

pacific2

  • New Member
  • *
  • Posts: 17
Re: DateTime for TChart Bottom Axis
« Reply #12 on: August 01, 2010, 12:27:54 pm »
ok Ask, I added in the code of my basic example:
chart1.BottomAxis.Marks.Source := chart1lineseries1.Source;

that works now.

many thanks

 

TinyPortal © 2005-2018