Page 1 of 1

TTeeXMLSource X-axis date value

Posted: Mon Dec 19, 2011 12:00 pm
by 16560757
Hello,

I have the following XML data structure:
<point X="20111207103917" Y="80" />
<point X="20111207104043" Y="80" />
<point X="20111207104121" Y="79" />

This is part of an XML that is required to be the data source for a line chart. When I set to Series1/General/Horizontal Axis Datetime checkbox to true i get a Division by zero exception. Please let me know if there is any way I can use this XML structure to correctly display the Data.
And another thing: I have built a chart with DateTime values on the X-Axis and random values on the Y-Axis (I used TeeChartOffice demo) and when I try to perform an export the X values seem to be missing from the exported XML. Please let me know if I have to perform some additional steps to get the full data.

Thank you in advance.

Re: TTeeXMLSource X-axis date value

Posted: Wed Dec 21, 2011 8:57 am
by yeray
Hello,

I've checked it with a simple example:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
    tmpDate: TDateTime;
begin
  Chart1.View3D:=false;

  Series1.XValues.DateTime:=true;
  tmpDate:=Today;
  for i:=0 to 9 do
  begin
    Series1.AddXY(tmpDate, random*1000);
    tmpDate:=IncDay(tmpDate);
  end;
end;
This is what I get when exporting the generated chart:
Exported XML wrote:<?xml version="1.0" encoding="ISO-8859-1"?>
<chart>
<series title="Series1" type="Point" color="#4466A3">
<points count="10">
<point X="40898" Y="473,781110486016"/>
<point X="40899" Y="349,795588292181"/>
<point X="40900" Y="795,892042340711"/>
<point X="40901" Y="66,6997157968581"/>
<point X="40902" Y="423,3904897701"/>
<point X="40903" Y="475,233346223831"/>
<point X="40904" Y="602,027327055112"/>
<point X="40905" Y="452,069552149624"/>
<point X="40906" Y="423,511422937736"/>
<point X="40907" Y="341,220206581056"/>
</points>
</series>

</chart>
rvc wrote:I have the following XML data structure:
<point X="20111207103917" Y="80" />
<point X="20111207104043" Y="80" />
<point X="20111207104121" Y="79" />
How are these XValues transformed? They look as DateTime strings in "yyyymmddhhnnss" format or something like this.

Re: TTeeXMLSource X-axis date value

Posted: Mon Dec 26, 2011 1:48 pm
by 16560757
Hello,

It seems to me your reply concerns exporting xml. My issue concerns creating chartseries from xml, where x-axis is datetime, formatted yyyymmddhhmmss.

Regards, Ronald

Re: TTeeXMLSource X-axis date value

Posted: Tue Dec 27, 2011 10:43 am
by yeray
Hi Ronald,

Excuse me. I haven't explained myself clearly enough.
In your XML, I see the X values (like 20111207103917) look as in 'yyyymmddhhnnss' format. When you load the XML, the values are loaded as doubles and when you set the XValues to DateTime the axis labels try to format DateTime values to strings, but the XValues aren't in the expected format.
So the question is how did you get those Xvalues in your XML file?

Re: TTeeXMLSource X-axis date value

Posted: Tue Dec 27, 2011 11:36 am
by 16560757
Aha, OK. So my datetime values are intrepreted as double. My goal is to create a chart where X-axis is of type TDateTime, ad which has seconds precision.

I create the XML myself, so I have control over that. How should I format dhe date time in the xml in order to get date time (including seconds) at the x-axis?

Also, I would like to use the zoom functionality. to retrieve appropriate data. I intend to use the OnZoom event. How can I get in that event the start and end value of the rect in X-axis coordinates (or: how can I get the start and end time the user selected)?

Thanks, Ronald

Re: TTeeXMLSource X-axis date value

Posted: Tue Dec 27, 2011 2:01 pm
by yeray
Hi Ronald,
rvc wrote:Aha, OK. So my datetime values are intrepreted as double. My goal is to create a chart where X-axis is of type TDateTime, ad which has seconds precision.

I create the XML myself, so I have control over that. How should I format dhe date time in the xml in order to get date time (including seconds) at the x-axis?
Knowing the day, month, year, hour, minute and second, you could use the EncodeDateTime function to get the datetime/double that corresponds to that date&time:
http://www.delphibasics.co.uk/RTL.asp?N ... deDateTime
rvc wrote:Also, I would like to use the zoom functionality. to retrieve appropriate data. I intend to use the OnZoom event. How can I get in that event the start and end value of the rect in X-axis coordinates (or: how can I get the start and end time the user selected)?
You can simply check the axes Minimum and Maximum properties at OnZoom/OnUndoZoom events. The following code works fine for me:

Code: Select all

procedure TForm1.Chart1Zoom(Sender: TObject);
begin
  Caption:='XMin: ' + FormatFloat('#0.00', Chart1.Axes.Bottom.Minimum);
  Caption:=Caption + ', XMax: ' + FormatFloat('#0.00', Chart1.Axes.Bottom.Maximum);
  Caption:=Caption + ', YMin: ' + FormatFloat('#0.00', Chart1.Axes.Left.Minimum);
  Caption:=Caption + ', YMax: ' + FormatFloat('#0.00', Chart1.Axes.Left.Maximum);
end;

Re: TTeeXMLSource X-axis date value

Posted: Tue Dec 27, 2011 3:24 pm
by 16560757
Hi Yeray,

Regarding datetime in XML, I would like to supply the x-axis values in the xml so that teechart can read that without me converting. That is what I meant by formatting datetime in xml.

Currently, I supply xml to teechart as below:

<series title="Heart Rate" type="Line" color="#FF0000">
<points count="164">
<point X="20111207103917" Y="80" />
etc.

My question: can I format the value for attribute "X" so that TeeChart will interpret the value as a TDateTime value? If so, how?

Regards, Ronald

Re: TTeeXMLSource X-axis date value

Posted: Wed Dec 28, 2011 9:13 am
by yeray
Hi Ronald,

Well, there are several options here:
- Having the source code version, you could modify the procedure TTeeXMLSource.LoadSeriesNode to convert the values from "yyyymmddhhnnss" format to TDateTime.
- You could implement a method to read the xml file, do the conversion saving a new xml file and load the new xml file after it.
- You could modify a little bit your xml format, giving the "yyyymmddhhnnss" values as labels (text). Then you'll be able to convert these strings to TDateTime and set them as XValues. Find below an example.

Here it is the modified xml.
<?xml version="1.0" encoding="ISO-8859-1"?>
<chart>
<series title="Series1" type="Point" color="#4466A3">
<points count="10">
<point text="2011/12/07 10:39:17" Y="80" />
<point text="2011/12/07 10:40:43" Y="80" />
<point text="2011/12/07 10:41:21" Y="79" />
</points>
</series>
</chart>
Note I had to change the "yyyymmddhhnnss" to "yyyy/mm/dd hh:nn:ss" so the StrToDateTime function can take it later (see the code below)

Code: Select all

uses TeeXML, DateUtils;

procedure TForm1.FormCreate(Sender: TObject);
var nSeries, nValue: Integer;
    tmpDate: TDateTime;
    tmpFormat: TFormatSettings;
begin
  with TTeeXMLSource.Create(Self) do
  begin
    FileName:='C:\tmp\test.xml';
    Chart:=Chart1;
    Load;
  end;

  //move datetime labels to XValues
  tmpFormat.ShortDateFormat:='yyyy/mm/dd';
  tmpFormat.DateSeparator:='/';
  tmpFormat.LongTimeFormat:='hh:nn:ss';
  tmpFormat.TimeSeparator:=':';

  for nSeries:=0 to Chart1.SeriesCount-1 do
  begin
    for nValue:=0 to Chart1[nSeries].Count-1 do
    begin
      tmpDate:=StrToDateTime(Chart1[nSeries].Labels.Labels[nValue], tmpFormat);
      Chart1[nSeries].XValue[nValue]:=tmpDate;
    end;

    Chart1[nSeries].XValues.DateTime:=true;
  end;
end;