几天来,我一直在尝试为 Highchart 图表创建多个系列,但无济于事。我尝试了许多示例,但无法形成所需的必要 json_encodeed。任何帮助都会很棒,显然我缺乏 PHP 技能。如果我以错误的方式解决这个问题,请随时提出建议。
这就是我想要结束的:
series: [{
name: 'Temperature',
data: [
[Date.UTC(1970, 9, 27), 0 ],
[Date.UTC(1970, 10, 10), 0.6 ],
[Date.UTC(1970, 10, 18), 0.7 ],
[Date.UTC(1970, 11, 2), 0.8 ]
]
}, {
name: 'Salinity',
data: [
[Date.UTC(1970, 9, 18), 0 ],
[Date.UTC(1970, 9, 26), 0.2 ]
]
}, {
name: 'Disolved Oxygen',
data: [
[Date.UTC(1970, 9, 9), 0 ],
[Date.UTC(1970, 9, 14), 0.15],
]
下面是我在这篇文章中的最新 PHP 尝试。我不确定如何使用 2 个字段来实现。
$chart1 = pg_query($connection, "SELECT sample_date, a FROM monitor_nutrient WHERE station_num_id = 1 ORDER BY sample_date ASC");
$row_a = array();
$row_a['name'] = 'Temperature';
while ($ra = pg_fetch_array($chart1)) {
$row_a['data'][] = $ra['a'];
}
$chart1 = pg_query($connection, "SELECT sample_date, b FROM monitor_nutrient WHERE station_num_id = 1 ORDER BY sample_date ASC");
$row_b = array();
$row_b['name'] = 'Salinity';
while ($rb = pg_fetch_array($chart1)) {
$row_b['data'][] = $rb['b'];
}
$chart1 = pg_query($connection, "SELECT sample_date, c FROM monitor_nutrient WHERE station_num_id = 1 ORDER BY sample_date ASC");
$row_c = array();
$row_c['name'] = 'Dissolved Oxygen';
while ($rc = pg_fetch_array($chart1)) {
$row_c['data'][] = $rc['c'];
}
$result = array();
array_push($result, $row_a);
array_push($result, $row_b);
array_push($result, $row_c);
print json_encode($result, JSON_NUMERIC_CHECK);