|
Problem with date in x-axis PHP |
Posted by Peter P on May-14-2013 15:21 |
|
Hi,
I'm currently trying to use the zooming and scrolling with track line graphic with my database but i have a lot of issues.
I've already done a simple line chart without any problem but with this one...i'm stuck.
My problem is : i can't find a way to show the date of every points in the x-axis.
The format of my date in the database is like : "2013-04-29 11:51:32"
I've already try to convert my date like : "2013, 4, 29" but it doesn't change anything.
i think the problem come from all these function used to complete the chart with random data.
I've maybe miss or don't understand something.
Anyway if anybody have an idea, any help would be greatly appreciated. |
Re: Problem with date in x-axis PHP |
Posted by Peter Kwan on May-15-2013 00:25 |
|
Hi Peter,
For "dates", in general, the date should be a date as according to your programming language. ("Dates" in a human language can be displayed for human reading, but may not be understandable by the computer.)
However, in PHP, there is no such thing as date (unlike other programming languages such as java.awt.Date in Java, System.DateTime in .NET, etc). So ChartDirector for PHP uses a special system in which date/time is represented as a number equal to the seconds elapsed since 1-1-0001 00:00:00. See:
http://www.advsofteng.com/doc/cdphp.htm#dateformat.htm
You may use the ChartDirector function chartTime or chartTime2 to construct such a date. If your data are from NySQL, there is a MySQL function UNIX_Timestamp to retreive the date/time as seconds elapsed since Jan 1, 1970 00:00:00 GMT, which you may convert to ChartDirector date/time using chartTime2. The brief steps are:
(1) Use the SQL "SELECT UNIX_Timestamp(myDateTimeColumn), ......." in your database code to retreive your date/time column in UNIX_Timestamp format.
(2) After retrieving the UNIX_Timestamp column into a PHP array, use the following code to convert it to ChartDirector date/time:
$myDateTimeArray = array_map("chartTime2", $myDateTimeArray);
You may then use the above array as the x-coordinates.
Hope this can help.
Regards
Peter Kwan |
|