无法获取我的阵列所需的模板 [英] Can't obtain the desired template for my arrays

查看:117
本文介绍了无法获取我的阵列所需的模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除[0] [等等]我要以.php得到这样我就可以单独使用它们,用人力车librairy创建图表。

I'd like to remove the [0] [and so on] I get with the .php so I can use them separately and create charts using RickShaw librairy.

这是目前JSON code I得到:

This is currently the JSON code i get :

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]是不同的线路

[0] to [3] are different lines

图书馆人力车似乎是最简单的我需要的东西。我可以插入像这样的系列:多个图表系列。谁能教我/告诉我怎样可以改变我的DATAS?

The library Rickshaw seems the easiest for what I need. I can insert series like this one : multiple charts series. Could anyone teach me/ tell me how i can change my datas ?

我想获得该模板(右上面贴的链接可见):

I'd like to obtain this template (as seen on the 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 } ],

这是我的实际的.php:

This is my actual .php :

<?php include 'connexion.php' ?>

<?php
////////////////// out_evo_tat   
$requete = $db->prepare('SELECT * FROM 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 as $key => $val){
    $out = array();
    foreach ($val as $key2 => $val2){
        $item = new stdClass;
        $item->x = $val2[0];
        $item->y = $val2[1];
        $out[] = $item;
    }
    $json[] = json_encode($out);
}
print_r($json);

?>

感谢您了很多。马修

推荐答案

由于我不知道你得到的值 $名称,我只是很难codeD值'东北'。下面,而不是像以前那样创造JSON值数组,从你的阵列产生你的JavaScript code $画面

Since I don't know where you're getting the value for $name, I just hardcoded the value 'Northeast.' The following, rather than creating an array of json values as before, generates your JavaScript code from your 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 as $key => $val){
    $js .= "\t\t{\n";
    $js .= "\t\t\tname: \"".$name."\",\n";
    $out = array();
    foreach ($val as $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;

输出:

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()
                }
                ]});

这篇关于无法获取我的阵列所需的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆