Steema Issues Database

Note: This database is for bugs and wishes only. For technical support help, if you are a customer please visit our online forums;
otherwise you can use StackOverflow.
Before using this bug-tracker we recommend a look at this document, Steema Bug Fixing Policy.



Bug 553 - Recognize automatically the datetime data when you export to TeeChart Javascript
Summary: Recognize automatically the datetime data when you export to TeeChart Javascript
Status: RESOLVED FIXED
Alias: None
Product: VCL TeeChart
Classification: Unclassified
Component: Export (show other bugs)
Version: 131119
Hardware: PC Windows
: High enhancement
Target Milestone: ---
Assignee: Steema Issue Manager
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-27 06:18 EST by sandra pazos
Modified: 2014-02-05 08:51 EST (History)
2 users (show)

See Also:
Chart Series: ---
Delphi / C++ Builder RAD IDE Version:


Attachments
Test project (VCL) (3.54 KB, application/x-zip-compressed)
2014-02-05 08:51 EST, david berneda
Details

Note You need to log in before you can comment on or make changes to this bug.
Description sandra pazos 2014-01-27 06:18:11 EST
I think the problems in bug 548 aren't related, for this reason I separated them.

2. Javascript data is written using my local (german) decimal separator, which is a comma. 

Sample for wrong data, produced by built in chart editor's export series data to JSON preview function: 
{ "chart": [
  {
   "series": {
   "name":"P4_NN_ROK",
   "color":"#0000FF",
   "point": [
     { "value":165,13445, "x":38831,750775463 },
     { "value":165,1343, "x":38831,7924537037 },
     { "value":165,1346, "x":38831,8341319444 },
     { "value":165,1329, "x":38831,8758101852 },

Btw: above example used a date axis. The windows date format you are writing here is pretty useless. Do you think it might be possible to export datetime data so they are automatically recognized by TeeChart Javascript?
Comment 1 david berneda 2014-02-05 06:10:35 EST
Partially fixed. 

Added support for datetime series values when exporting a chart to JavaScript format using TeeJavaScript.pas "TJavaScriptExportFormat" class.

See attachment with test VCL project.

Note: The latest TeeChart source code (Feb-5th or greater) is required.

Pending: DateTime support when exporting to JSON format.
Comment 2 david berneda 2014-02-05 08:50:01 EST
Fixed. Added a new property to TSeriesDataJSON class to determine which format to use for datetime values.

It seems there's no standard about datetime data in JSON format.
http://markembling.info/2011/07/json-date-time

So, by default datetime values will be simply exported as timestamps (Delphi date timestamps), and the new property allows exporting to JavaScript Date format (milliseconds since 1-1-1970):

uses TeeStore, TeeStringsEditor;

procedure TForm1.Button2Click(Sender: TObject);
var s : String;
begin
  with TSeriesDataJSON.Create(Chart1) do
  try
    DateTimeFormat:=jdJavaScript;

    s:=AsString;
    
    TeeEditStrings(Self,s);
  finally
    Free;
  end;
end;


However, datetime values in JSON format cannot be imported automatically because the browser JSON parser does not know that numbers are datetime values.

So, a conversion should be done in JavaScript from JSON data to valid dates, like:

series.data.x[0] = new Date(series.data.x[0]);

This will make the chart axes to recognize series data as datetime values.
Comment 3 david berneda 2014-02-05 08:51:34 EST
Created attachment 83 [details]
Test project (VCL)