PDA

View Full Version : From php timestamp to Extjs date format



Niugeo
26 Nov 2010, 7:42 AM
Hello,
I have in input some timestamps records that my PHP script take from a DB. I want to plot these values on a TimeAxis while along the yAsis I'll plot other records.
Let's say timestamps record on xAxis and Packet_Loss along yAsxis.
This is my code. At the first step I take the result of the query and encode it by Json_encode...
----------------------
while($riga=mysql_fetch_assoc($risultato)){

array_push($dati, array(
'Vp'=>$riga['Vp'],
'Instant'=>$riga['Instant'],
'Delay'=>$riga['Delay'],
'Loss'=>$riga['Loss'],
'Jitter'=>$riga['Jitter'],
));

}
$storePHP=json_encode($dati);
...
...
...
...var store = new Ext.data.JsonStore({
fields:['Vp',{name:'Instant', type:'Date', format:'Y-m-d H:i:s'},'Delay','Loss','Jitter',],
data: <?php echo($storePHP);?>
});
.....
.....
.....xAxis: new Ext.chart.TimeAxis({
displayName: 'Instant',
labelRenderer: function(date){ return data.format('Y-m-d H:i:s'); }
}),

This code doesn't display the chart. Instead if I change type "Date" to "data" and remove the TimeAxis everythink magically works, but of course along the xAxis I see the string "2010-11-26 16:23:00".
Can somebody help me and explain where I'm wrong?
Also the records to plot are houndred and houndred, so I need to display just, let say, one timestamp value every hour, and in "H:i" format.
Please help me!
Thanks you all.
Eugenio.

Condor
26 Nov 2010, 7:58 AM
{name:'Instant', type:'date', dateFormat:'Y-m-d H:i:s'}

(and does PHP actually send in Y-m-d H:i:s format?)

Niugeo
26 Nov 2010, 8:29 AM
Hi Condor,
thanks a lot for your help.Now my code works nearly good :-)
The PHP script does a query to a MySQL that I've created on a web server,and the records inside it are saved ad "TIMESTAMP" value.
If I do an echo of a record I see [26-11-2010 17:18:02].
So PHP send in this format (I suppose....I'm a beginner developer :-) ).
Here the resultin chart.When the mouse move overa row I can see the xAxis value(the timestamp value),but why some rows (like the two I've marked in brown) are too large?

23554

Condor
26 Nov 2010, 8:37 AM
1. Your image is too small to see clearly (try uploading it to imageshack.us and posting a link).
2. What is the data for this chart?

Niugeo
26 Nov 2010, 8:58 AM
sigh, imageshack.us domain is blocked here, anyway I try to post this image, maybe is better.
The data is number...you mean this??
----------------
yAxis: new Ext.chart.NumericAxis({
displayName: 'Delay',
maximum:150,
HideOverlappingLabels: true,
labelRenderer : Ext.util.Format.numberRenderer('0.0')
---------------
re-edit
Here the immage
http://img219.imageshack.us/img219/5713/wrongn.png
(http://img219.imageshack.us/i/wrongn.png/)