可以't为我的数组获得所需的模板
Can't obtain the desired template for my arrays
我想删除我在.php中得到的[0]等],这样我就可以单独使用它们,并使用RickShaw库创建图表。
这是我目前得到的JSON代码:
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]是不同的线
图书馆里的人力车似乎是我所需要的最简单的。我可以插入这样的系列:多个图表系列。有人能教我/告诉我如何更改数据吗?
我想获得这个模板(如上面发布的链接所示):
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:
<?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);
?>
非常感谢。Mathieu
由于我不知道从哪里得到$name
的值,所以我只硬编码了值'Northeast'以下内容不是像以前那样创建json值数组,而是从数组$tableau
:生成JavaScript代码
$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()
}
]});
相关文章:
- 如果数组仍在执行,async.forEach()将运行我添加到数组中的新元素
- 我可以使用JS一次使用JSON数组中的一个字符串吗
- I'我试图用javascript制作文本框,并将输入的值发送到数组中的文本框中进行添加
- 我可以限制我添加到数组中的项目数量吗
- 我怎样才能给数组中的每个对象赋予它们自己的键
- 数组中的对象,我如何访问它们
- 我想使用Javascript中的循环在HTML中的特定id中显示数组中的多个对象
- 我如何才能使数组中的按钮只对其作出响应'使用javascript的自己的包装器
- 我的函数不会返回要保存在数组中的对象
- 当数组中的某个函数没有返回promise时,我可以使用$q.all吗
- 获取我的数组中的每个 ID 映像 src
- 我将如何在 HTML 中将数组中的所有元素显示为可点击的对象
- 如何用javascript创建三维数组我想把数据插入数组中,这有助于我的代码
- 如何在我的setAttribute函数中构建数组中的子函数
- 我看不到Javascript数组中的图像
- 我如何获得 Javascript 中关联数组和常规数组之间的区别
- 我应该如何使这个多维数组中的名称加粗
- 我应该更改数组中的字符串
- 我如何修改它以使用数组中的所有项目
- (EloquentJavascript:第4章)反转数组-我的版本有什么问题吗