我的任務(wù)是解決如何將 JSON 編碼更改為數(shù)組字符串,請查看下面的代碼:我有["11:00"]["09:00"]["01:00"]["12:00"]["11:00"]["10:00"]["01:00"]["00:00"]["23:00"]["22:00"]如何改變它成為["11:00","09:00","01:00","11:00","10:00","01:00","00:00","23:00","22:00"]我的stats.php樣子是這樣的:out .= ' <div class="col-lg-5 col-md-5 col-sm-5 col-lg-offset-1 col-md-offset-1 col-sm-offset-1" style="height: 300px">'; $out .= ' <div class="chartjs-size-monitor">'; $out .= ' <div class="chartjs-size-monitor-expand">'; $out .= ' <div class=""></div>'; $out .= ' </div>'; $out .= ' <div class="chartjs-size-monitor-shrink">'; $out .= ' <div class=""></div>'; $out .= ' </div>'; $out .= ' </div>'; $out .= ' <canvas id="myChart2" class="canpas chartjs-render-monitor" style="display: block; width: 454px; height: 300px;" width="454" height="300"></canvas>'; $out .= ' </div>';$graph_query = mssql_query("SELECT TOP 100 Convert(nvarchar,dtDate,108) AS Date, serial, nAverageUser, nMaxUser FROM tbl_ServerUser_Log ORDER BY serial DESC"); $i = 1; while ($graph = mssql_fetch_array($graph_query)) { $graph['nMaxUser'] = round($graph['nMaxUser'] * $percent_inc); $graph['nAverageUser'] = round($graph['nAverageUser'] * $percent_inc); $serie1->addPoint(new Point($graph['Date'], $graph['nMaxUser'])); $serie2->addPoint(new Point($graph['Date'], $graph['nAverageUser'])); $date = date('H:i', strtotime($graph['Date'])); $convert = json_encode(str_split($date, 5)); // $convert = str_replace('][','',$convert); echo $convert; }我只想顯示從手動(dòng)值到從 SQL 服務(wù)器捕獲的查詢值的圖表。預(yù)先感謝您回答我的問題。
1 回答

牛魔王的故事
TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超3個(gè)贊
不要每次循環(huán)都回顯 JSON。將時(shí)間放在一個(gè)數(shù)組中,并在末尾回顯 JSON。
$dates = [];
while ($graph = mssql_fetch_array($graph_query)) {
$graph['nMaxUser'] = round($graph['nMaxUser'] * $percent_inc);
$graph['nAverageUser'] = round($graph['nAverageUser'] * $percent_inc);
$serie1->addPoint(new Point($graph['Date'], $graph['nMaxUser']));
$serie2->addPoint(new Point($graph['Date'], $graph['nAverageUser']));
$date = date('H:i', strtotime($graph['Date']));
$dates[] = $date;
echo $convert;
}
echo json_encode($dates);
- 1 回答
- 0 關(guān)注
- 139 瀏覽
添加回答
舉報(bào)
0/150
提交
取消