php - Can't obtain the desired template for my arrays -


i'd remove [0] [and on] .php can use them separately , create charts using rickshaw librairy.

this json code :

array ( [0] => [{"x":"0","y":"35"},{"x":"1","y":"34"},{"x":"2","y":"36"},{"x":"3","y":"35"},{"x":"4","y":"40"},{"x":"5","y":"35"},{"x":"6","y":"37"},{"x":"7","y":"40"},{"x":"8","y":"45"},{"x":"9","y":"46"},{"x":"10","y":"55"},{"x":"11","y":"63"},{"x":"12","y":"61"},{"x":"13","y":"45"},{"x":"14","y":"48"},{"x":"15","y":"49"},{"x":"16","y":"45"},{"x":"17","y":"44"},{"x":"18","y":"52"},{"x":"19","y":"43"},{"x":"20","y":"37"},{"x":"21","y":"36"},{"x":"22","y":"37"},{"x":"23","y":"34"}]  [1] => [{"x":"0","y":"10"},{"x":"1","y":"15"},{"x":"2","y":"13"},{"x":"3","y":"15"}, "x":"4","y":"14"},{"x":"5","y":"16"},{"x":"6","y":"17"},{"x":"7","y":"25"},{"x":"8","y":"23"},{"x":"9","y":"24"},{"x":"10","y":"25"},{"x":"11","y":"28"},{"x":"12","y":"27"},{"x":"13","y":"21"},{"x":"14","y":"23"},{"x":"15","y":"19"},{"x":"16","y":"18"},{"x":"17","y":"16"},{"x":"18","y":"15"},{"x":"19","y":"14"},{"x":"20","y":"15"},{"x":"21","y":"16"},{"x":"22","y":"15"},{"x":"23","y":"16"}]  [2] => [{"x":"0","y":"45"},{"x":"1","y":"49"},{"x":"2","y":"49"},{"x":"3","y":"50"},{"x":"4","y":"54"},{"x":"5","y":"51"},{"x":"6","y":"54"},{"x":"7","y":"65"},{"x":"8","y":"68"},{"x":"9","y":"70"},{"x":"10","y":"80"},{"x":"11","y":"91"},{"x":"12","y":"88"},{"x":"13","y":"66"},{"x":"14","y":"71"},{"x":"15","y":"68"},{"x":"16","y":"63"},{"x":"17","y":"60"},{"x":"18","y":"67"},{"x":"19","y":"57"},{"x":"20","y":"52"},{"x":"21","y":"52"},{"x":"22","y":"52"},{"x":"23","y":"50"}]  [3] => [{"x":"0","y":"10"},{"x":"1","y":"15"},{"x":"2","y":"12"},{"x":"3","y":"5"},{"x":"4","y":"9"},{"x":"5","y":"15"},{"x":"6","y":"45"},{"x":"7","y":"125"},{"x":"8","y":"345"},{"x":"9","y":"256"},{"x":"10","y":"312"},{"x":"11","y":"345"},{"x":"12","y":"299"},{"x":"13","y":"165"},{"x":"14","y":"354"},{"x":"15","y":"368"},{"x":"16","y":"254"},{"x":"17","y":"213"},{"x":"18","y":"312"},{"x":"19","y":"165"},{"x":"20","y":"54"},{"x":"21","y":"32"},{"x":"22","y":"10"},{"x":"23","y":"5"}] [4] => [{"x":"0","y":"2"},{"x":"1","y":"3"},{"x":"2","y":"2"},{"x":"3","y":"1"},{"x":"4","y":"1"},{"x":"5","y":"2"},{"x":"6","y":"3"},{"x":"7","y":"15"},{"x":"8","y":"45"},{"x":"9","y":"27"},{"x":"10","y":"40"},{"x":"11","y":"42"},{"x":"12","y":"35"},{"x":"13","y":"18"},{"x":"14","y":"42"},{"x":"15","y":"40"},{"x":"16","y":"30"},{"x":"17","y":"25"},{"x":"18","y":"40"},{"x":"19","y":"20"},{"x":"20","y":"6"},{"x":"21","y":"4"},{"x":"22","y":"2"},{"x":"23","y":"1"}] ) 

[0] [3] different lines

the library rickshaw seems easiest need. can insert series 1 : multiple charts series. teach me/ tell me how can change datas ?

i'd obtain template (as seen on link posted right above) :

var graph = new rickshaw.graph( {         element: document.queryselector("#chart"),         width: 540,         height: 250,         series: [                 {                         name: "northeast",                         data: [ { x: -1893456000, y: 25868573 }, { x: -1577923200, y: 29662053 }, { x: -1262304000, y: 34427091 }, { x: -946771200, y: 35976777 }, { x: -631152000, y: 39477986 }, { x: -315619200, y: 44677819 }, { x: 0, y: 49040703 }, { x: 315532800, y: 49135283 }, { x: 631152000, y: 50809229 }, { x: 946684800, y: 53594378 }, { x: 1262304000, y: 55317240 } ],                         color: palette.color()                 },                 {                         name: "midwest",                         data: [ { x: -1893456000, y: 29888542 }, { x: -1577923200, y: 34019792 }, { x: -1262304000, y: 38594100 }, { x: -946771200, y: 40143332 }, { x: -631152000, y: 44460762 }, { x: -315619200, y: 51619139 }, { x: 0, y: 56571663 }, { x: 315532800, y: 58865670 }, { x: 631152000, y: 59668632 }, { x: 946684800, y: 64392776 }, { x: 1262304000, y: 66927001 } ], 

this actual .php :

<?php include 'connexion.php' ?>  <?php ////////////////// out_evo_tat    $requete = $db->prepare('select * out_evo_tat'); $requete->execute();  while($row = $requete->fetch()) {       $tableau[]= array (         array($row['heure'],$row['tat_chaine']),         array($row['heure'], $row['tat_prea']),         array($row['heure'], $row['tat_global']),         array($row['heure'], $row['nbr_tests']),         array($row['heure'], $row['nbr_tubes'])         );   }  array_unshift($tableau, null); $tableau = call_user_func_array('array_map', $tableau); $json = array(); foreach ($tableau $key => $val){     $out = array();     foreach ($val $key2 => $val2){         $item = new stdclass;         $item->x = $val2[0];         $item->y = $val2[1];         $out[] = $item;     }     $json[] = json_encode($out); } print_r($json);  ?> 

thank lot. mathieu

since don't know you're getting value $name, hardcoded value 'northeast.' following, rather creating array of json values before, generates javascript code array $tableau:

$name = 'northeast'; array_unshift($tableau, null); $tableau = call_user_func_array('array_map', $tableau); $js = <<<eotaaa var graph = new rickshaw.graph( {     element: document.queryselector("#chart"),     width: 540,     height: 250,     series: [  eotaaa; foreach ($tableau $key => $val){     $js .= "\t\t{\n";     $js .= "\t\t\tname: \"".$name."\",\n";     $out = array();     foreach ($val $key2 => $val2){         $item = new stdclass;         $item->x = $val2[0];         $item->y = $val2[1];         $out[] = $item;     }     $js .= "\t\t\tdata: ".str_replace('"', '', json_encode($out)).",\n";     $js .= "\t\t\tcolor: palette.color()\n";     $js .= "\t\t},\n"; } $js = rtrim($js, ",\n");//remove last comma $js .= "\n\t\t]});\n"; echo $js; 

output:

var graph = new rickshaw.graph( {         element: document.queryselector("#chart"),         width: 540,         height: 250,         series: [                 {                     name: "northeast",                     data: [{x:0,y:35},{x:1,y:34},{x:2,y:36},{x:3,y:35}],                     color: palette.color()                 },                 {                     name: "northeast",                     data: [{x:0,y:10},{x:1,y:15},{x:2,y:13},{x:3,y:15}],                     color: palette.color()                 },                 {                     name: "northeast",                     data: [{x:0,y:45},{x:1,y:49},{x:2,y:49},{x:3,y:50}],                     color: palette.color()                 },                 {                     name: "northeast",                     data: [{x:0,y:10},{x:1,y:15},{x:2,y:12},{x:3,y:5}],                     color: palette.color()                 },                 {                     name: "northeast",                     data: [{x:0,y:2},{x:1,y:3},{x:2,y:2},{x:3,y:1}],                     color: palette.color()                 }                 ]}); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -