我一直试图为Highchart图创建多个系列几天无济于事。我尝试过很多例子,但是我无法形成必要的json_encode。任何帮助都会很棒,显然我的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],
]
以下是我this post的最新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);