我正在尝试使用 php/mysql 在 morrisjs 中构建图形,并且需要输出具有以下格式的对象。它应该对期间日期进行分组,然后列出其后面的名称以匹配结果:
{period: "2019-02-06 12:00:00", shelly: 2147483647, debra: 1240996571, sally: 2147483647, bill: 2147483647, bob: 619685085, jim: 126614618},
{period: "2019-02-06 12:30:00", shelly: 2147483647, debra: 1240996571, sally: 2147483647, bill: 2147483647, bob: 619685085, jim: 126614618},
{period: "2019-02-06 13:00:00", shelly: 2147483647, debra: 1240996571, sally: 2147483647, bill: 2147483647, bob: 619685085, jim: 126614618}
PHP:
while ($row = mysqli_fetch_array($poolChart)) {
$chart_data .= "{ \"period\": \"".$row["StatsHistoryTime"]."\", \"name\": \"".$row["name"]."\", \"hashrate\":".$row["hashrate"]."}, ";
}
$chart_data = substr($chart_data, 0, -2);
目前我的输出看起来像这样
[
{
"period": "2019-02-06 12:00:00",
"name": "shelly",
"hashrate": 2147483647
},
{
"period": "2019-02-06 12:00:00",
"name": "debra",
"hashrate": 1240996571
},
{
"period": "2019-02-06 12:00:00",
"name": "sally",
"hashrate": 2147483647
},
{
"period": "2019-02-06 12:00:00",
"name": "bill",
"hashrate": 2147483647
}
{
"period": "2019-02-06 12:30:00",
"name": "shelly",
"hashrate": 2147483647
},
{
"period": "2019-02-06 12:30:00",
"name": "debra",
"hashrate": 1460613388
},
{
"period": "2019-02-06 12:30:00",
"name": "sally",
"hashrate": 2147483647
},
{
"period": "2019-02-06 12:30:00",
"name": "bill",
"hashrate": 2147483647
}
]