我有一个疑问
$array1 = $wpdb->get_results( "SELECT timestamp,temp FROM $table_name ORDER BY id desc LIMIT 8", ARRAY_A );
$data1 = json_encode($array1);
echo $data1;
结果回响如下:
[
{"timestamp":"2020-07-26 09:50:25","temp":"26.31"},
{"timestamp":"2020-07-26 09:40:29","temp":"26.37"},
{"timestamp":"2020-07-26 09:30:33","temp":"26.31"},
{"timestamp":"2020-07-26 09:20:37","temp":"26.43"},
{"timestamp":"2020-07-26 09:19:56","temp":null},
{"timestamp":"2020-07-26 08:54:54","temp":"26.37"},
{"timestamp":"2020-07-26 08:44:58","temp":"26.18"},
{"timestamp":"2020-07-26 08:35:02","temp":"26.25"}
]
我想用它作为图表的输入。
Chartist.js(也包括moments.js)给出的模板如下所示:
var chart = new Chartist.Line('.ct-chart', { series: [ {
name: 'series-1',
data: [
{x: new Date(143134652600), y: 53},
{x: new Date(143234652600), y: 40},
{x: new Date(143340052600), y: 45},
{x: new Date(143366652600), y: 40},
{x: new Date(143410652600), y: 20},
{x: new Date(143508652600), y: 32},
{x: new Date(143569652600), y: 18},
{x: new Date(143579652600), y: 11}
]
},
等等。如何在 php 中转换此数组/用 x 替换时间戳/用 y 替换时间戳并在 javascript 中使用它(在循环中?)?
斯蒂芬大帝