Actual value of XValue

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
MVBobj
Newbie
Newbie
Posts: 34
Joined: Fri Jul 17, 2015 12:00 am
Contact:

Actual value of XValue

Post by MVBobj » Tue Aug 18, 2015 5:48 pm

Hi,

I have a DBChart with the X-Axis as DateTime. In an OnSeriesClick event I know how to display the Y-Value but how do I display the actual X-Value? Not the ValueIndex or the XLabel[ValueIndex] but the actual date from the underlying CrossTab data series at that ValueIndex. Without formatting.

Every attempt I make at this returns the ValueIndex or the Label.

I've tried variations of:

Series1.XValueToText(Series1.XValue[ValueIndex])
DBChart1.BottomAxis.CalcPosPoint(X))
DBChart1[SeriesIndex].XValues[ValueIndex]
DBChart1[Series.SeriesIndex].XLabel[ValueIndex]
DBChart1[Series.SeriesIndex].XValueToText(ValueIndex)
DBChart1[Series.SeriesIndex].XValueToText(DBChart1[Series.SeriesIndex].XValue[ValueIndex])
DBChart1[Series.SeriesIndex].XValue[ValueIndex]
DBChart1[Series.SeriesIndex].XValues.Items[ValueIndex]

and nothing gives me the date except XLabel and I want the date from the series that SET that XLabel.

How do I do this?

Thanks.

Yeray
Site Admin
Site Admin
Posts: 9514
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Actual value of XValue

Post by Yeray » Wed Aug 19, 2015 10:00 am

Hello,

Note a TDateTime is actually a Double. So you need to format it or you'll just get a number.
Try this:

Code: Select all

FormatDateTime('dd/mm/yyy hh:nn:sss', DBChart1[SeriesIndex].XValue[ValueIndex]);
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

MVBobj
Newbie
Newbie
Posts: 34
Joined: Fri Jul 17, 2015 12:00 am
Contact:

Re: Actual value of XValue

Post by MVBobj » Wed Aug 19, 2015 12:57 pm

Ok - the first segment of the series should return "31/08/2004" but instead returns "30/12/1899 00:00:00" because DBChart1[SeriesIndex].XValue[ValueIndex] is returning "0". Second segment returns "1", third segment returns "2", etc.

Similarly:

Segment Date Actual date
1 31/12/1899 30/09/2004
2 01/01/1900 31/10/2004
3 02/01/1900 30/11/2004
4 03/01/1900 31/12/2004

How do I get this to return the actual date? Do I have a setting wrong someplace?

Thanks.

Yeray
Site Admin
Site Admin
Posts: 9514
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Actual value of XValue

Post by Yeray » Wed Aug 19, 2015 2:42 pm

Hello,

You may have added the values with label but, if you are getting 0, 1, 2,... in the XValues array it's probably because you added the values in your series without XValue; this is through Add() function or similar.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

MVBobj
Newbie
Newbie
Posts: 34
Joined: Fri Jul 17, 2015 12:00 am
Contact:

Re: Actual value of XValue

Post by MVBobj » Wed Aug 19, 2015 5:58 pm

There is 1 series: Series1 and the Data Source is set to CrossTab with the Dataset set to a SQL query returning a Location, Total and AsOfDate . It is grouped by location (6 locations) so that the result is 6 series with the total summed for each date and the AsOfDate. Labels is set to AsOfDate. It has a Total (Y-Axis) and the AsOfDate (X-Axis).

How can I get the AsOfDate from the series? Is it because of the CrossTab and/or the chart knowing that AsOfDate is the X-Label that only the ValueIndex is returned?

Thanks.

Yeray
Site Admin
Site Admin
Posts: 9514
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Actual value of XValue

Post by Yeray » Thu Aug 20, 2015 2:50 pm

Hello,

Could you please arrange a simple example project we can run as-is to reproduce the problem here?
Thanks in advance.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

MVBobj
Newbie
Newbie
Posts: 34
Joined: Fri Jul 17, 2015 12:00 am
Contact:

Re: Actual value of XValue

Post by MVBobj » Fri Aug 21, 2015 2:10 pm

I enclose a sample project.

There are 2 examples - 2 series - one loaded with the "Add" command and one with Data Source set to Dataset. If you click on a segment in either series the results are the same. A date returned is only correct if from the XLabel. Everything else I do results in a date of 1899 or 1900 because the ValueIndex is returned instead of a date in Double format.

I would like to get the X-Axis date from the series rather than have to get the ValueIndex and go to the original data source for it.

How do I do this?
Attachments
TeeChartXValueResponse.zip
(17.61 KiB) Downloaded 696 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Actual value of XValue

Post by Narcís » Tue Aug 25, 2015 10:41 am

Hello,

Even I suggested you (via email) to use interpolation as I posted here, this will not work in your project because your series don't provide DateTime values to your series as X values, you only provide them as axis labels. What happens here is that you feed Y values and labels to your series. TeeChart fills X values with sequential values: 0, 1, 2, 3, etc. Given you set your series XValues to be DateTime and looking at

Code: Select all

System.TDateTime
, what you get are the DateTime representation of those sequential values TeeChart uses as X values. To obtain the DateTime values you expect, you should populate your series with those values. I have modified your project (find it attached) doing that for the manually populated series.
Attachments
TeeChartXValue.zip
(7.17 KiB) Downloaded 698 times
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

MVBobj
Newbie
Newbie
Posts: 34
Joined: Fri Jul 17, 2015 12:00 am
Contact:

Re: Actual value of XValue

Post by MVBobj » Tue Aug 25, 2015 4:52 pm

Hi,

So - how do I do this from a dataset (as a data-aware control)? The issue here is that we don't want to do ANYTHING manually! A floating point number and a date (in date form - not text) are being pulled from a database table and the data source is set to crosstab. In my example, in the manually added data, it is clear where the text xvalues come from - but how is it that I can't get the actual dates from the version of the series loaded via crosstab?

How do I do this from a dataset without manually adding anything?

Thanks.

MVBobj
Newbie
Newbie
Posts: 34
Joined: Fri Jul 17, 2015 12:00 am
Contact:

Re: Actual value of XValue

Post by MVBobj » Tue Aug 25, 2015 6:54 pm

Ok - I think I see what might be happening here.

The Data Source is set to CrossTab and in the Dataset there are floating point values loaded as YValues, there is a "Group by" set to the data field I want to group by.

The X-Axis has a Dataset date field assigned as XValues but that date field is identified in the "Labels" list box. I'm guessing that the actual date values are being assigned to the series XValues as text labels rather than as the original date values I'm expecting.

How do I get the date values for the X-Axis loaded into the series in their original format so that they can be individually retrieved via a ChartClickSeries event?

Thanks.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Actual value of XValue

Post by Narcís » Wed Aug 26, 2015 2:20 pm

Hello,

I see, the problem is setting XValues for the second series on the OnCreate event. Commenting out the line below solves the problem.

Code: Select all

  for I := 0 to DBChart[1].Count - 1 do
  begin
    DBChart[1].Labels[i]:=DateToStr(DBChart[1].XValues[i]);
    //DBChart[1].XValues[i]:=i;
  end;
For values being visible you may also need to add the line below at the bottom of Button2Click method.

Code: Select all

  DBChart.Axes.Bottom.Automatic:=True;
Making those changes will require changes on the scroll segments calculation and axes settings though.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply