I am trying to get data from a database and populate the Highstock charts with it, previously I was assigning the 'data: ' option of the chart to the datatable that was generated from the search, I realised the data would plot the series but in a random order. Here is what I have tried:
function json_original()
{
$sql = "SELECT UNIX_TIMESTAMP(t1.`date`) as `date`, sum(t1.`present`) as `present` from record_attendance_cell t1 group by t1.`date`";
$present_g = $this->db->query($sql)->result_array();
foreach($present_g as $row) {
$value = $row['present'];
$datetime = $row['date'] * 1000; // convert from Unix timestamp to JavaScript time
$data[] = "[$datetime, $value]";
// echo join($data, ',');
$result = json_encode($data);
echo $result;
}
}
The result of the code has many iterations of the same data: ["[1483833600000, 2]"]["[1483833600000, 2]","[1484697600000, 1]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]","[1502492400000, 3]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]","[1502492400000, 3]","[1503010800000, 3]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]","[1502492400000, 3]","[1503010800000, 3]","[1503183600000, 30]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]","[1502492400000, 3]","[1503010800000, 3]","[1503183600000, 30]","[1503270000000, 12]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]","[1502492400000, 3]","[1503010800000, 3]","[1503183600000, 30]","[1503270000000, 12]","[1503356400000, 10]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]","[1502492400000, 3]","[1503010800000, 3]","[1503183600000, 30]","[1503270000000, 12]","[1503356400000, 10]","[1503961200000, 9]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]","[1502492400000, 3]","[1503010800000, 3]","[1503183600000, 30]","[1503270000000, 12]","[1503356400000, 10]","[1503961200000, 9]","[1506985200000, 3]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]","[1502492400000, 3]","[1503010800000, 3]","[1503183600000, 30]","[1503270000000, 12]","[1503356400000, 10]","[1503961200000, 9]","[1506985200000, 3]","[1507158000000, 3]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]","[1502492400000, 3]","[1503010800000, 3]","[1503183600000, 30]","[1503270000000, 12]","[1503356400000, 10]","[1503961200000, 9]","[1506985200000, 3]","[1507158000000, 3]","[1508367600000, 31]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]","[1502492400000, 3]","[1503010800000, 3]","[1503183600000, 30]","[1503270000000, 12]","[1503356400000, 10]","[1503961200000, 9]","[1506985200000, 3]","[1507158000000, 3]","[1508367600000, 31]","[1509408000000, 3]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]","[1502492400000, 3]","[1503010800000, 3]","[1503183600000, 30]","[1503270000000, 12]","[1503356400000, 10]","[1503961200000, 9]","[1506985200000, 3]","[1507158000000, 3]","[1508367600000, 31]","[1509408000000, 3]","[1509667200000, 8]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]","[1502492400000, 3]","[1503010800000, 3]","[1503183600000, 30]","[1503270000000, 12]","[1503356400000, 10]","[1503961200000, 9]","[1506985200000, 3]","[1507158000000, 3]","[1508367600000, 31]","[1509408000000, 3]","[1509667200000, 8]","[1510790400000, 10]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]","[1502492400000, 3]","[1503010800000, 3]","[1503183600000, 30]","[1503270000000, 12]","[1503356400000, 10]","[1503961200000, 9]","[1506985200000, 3]","[1507158000000, 3]","[1508367600000, 31]","[1509408000000, 3]","[1509667200000, 8]","[1510790400000, 10]","[1511049600000, 12]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]","[1502492400000, 3]","[1503010800000, 3]","[1503183600000, 30]","[1503270000000, 12]","[1503356400000, 10]","[1503961200000, 9]","[1506985200000, 3]","[1507158000000, 3]","[1508367600000, 31]","[1509408000000, 3]","[1509667200000, 8]","[1510790400000, 10]","[1511049600000, 12]","[1511395200000, 12]"]["[1483833600000, 2]","[1484697600000, 1]","[1491174000000, 1]","[1497222000000, 22]","[1502319600000, 11]","[1502492400000, 3]","[1503010800000, 3]","[1503183600000, 30]","[1503270000000, 12]","[1503356400000, 10]","[1503961200000, 9]","[1506985200000, 3]","[1507158000000, 3]","[1508367600000, 31]","[1509408000000, 3]","[1509667200000, 8]","[1510790400000, 10]","[1511049600000, 12]","[1511395200000, 12]","[1514764800000, 2]"]
The data should look like this: Format
Reference document: High Charts