I am trying to generate a graph from an array which contains other associative arrays inside it. All the arrays that are inside the main array have the same keys.
Currently, the graphing is done using variables that keep an array with the values to graph them, each variable represents a series or "line" of the graph.
//Start of the code for the series of the graph
data: {
//array that contains the labels of each data series
labels: [
<?php
$p = "";
foreach ($categoryArray as $d) {
echo "'" . $d['label'] . "',";
}
?>
],
//arrays of the data series to plot
datasets: [{
//first series
data: [
<?php
$t = "";
foreach ($dataseries1 as $d) {
echo $d['value'] . ",";
}
?>
],
label: "PTemp_C_Avg",
borderColor: "#000000",
pointRadius: 0,
fill: false,
lineTension: 0
},
//second series
data: [
<?php
$t = "";
foreach ($dataseries1 as $d) {
echo $d['value'] . ",";
}
?>
],
label: "PTemp_C_Avg",
borderColor: "#000000",
pointRadius: 0,
fill: false,
lineTension: 0
},
//n series
......
.......
.......
As you can see in the previous code you must make the code for each series, however this limits the number of series that can be plotted, so I would like to be able to generate the graph from associative arrays as shown below :
Array ( [0] =>
Array (
[5cad0e5a00d510066802a0da] => MongoDB\BSON\ObjectId Object ( [oid] => 5cad0e5a00d510066802a0db )
[NS5c53244700d5101cb4008757] => 5c53244700d5101cb4008757
[TIMESTAMP] => MongoDB\BSON\UTCDateTime Object ( [milliseconds] => 1532939400000 )
[RECORD] => 276
[PTemp_C_Avg] => 7.261
[T0_10cm_Avg] => 21.32
[T0_10cm_Max] => 25.47
[T0_10cm_Min] => 15.98
[T1_1m_Avg] => 27.36
[T1_1m_Max] => 35.4
[T1_1m_Min] => 20.23
[T2_2m_Avg] => 31.77
[T2_2m_Max] => 39.18
[T2_2m_Min] => 24.4
)
[1] =>
Array (
[5cad0e5a00d510066802a0da] => MongoDB\BSON\ObjectId Object ( [oid] => 5cad0e5a00d510066802a0dc )
[NS5c53244700d5101cb4008757] => 5c53244700d5101cb4008757
[TIMESTAMP] => MongoDB\BSON\UTCDateTime Object ( [milliseconds] => 1532940300000 )
[RECORD] => 277
[PTemp_C_Avg] => 7.215
[T0_10cm_Avg] => 21.18
[T0_10cm_Max] => 27.68
[T0_10cm_Min] => 14.7
[T1_1m_Avg] => 27.27
[T1_1m_Max] => 32.6
[T1_1m_Min] => 20.53
[T2_2m_Avg] => 32.04
[T2_2m_Max] => 38.94
[T2_2m_Min] => 25.3
)
[2] =>
Array (
[5cad0e5a00d510066802a0da] => MongoDB\BSON\ObjectId Object ( [oid] => 5cad0e5a00d510066802a0dd )
[NS5c53244700d5101cb4008757] => 5c53244700d5101cb4008757
[TIMESTAMP] => MongoDB\BSON\UTCDateTime Object ( [milliseconds] => 1532941200000 )
[RECORD] => 278
[PTemp_C_Avg] => 7.218
[T0_10cm_Avg] => 21.07
[T0_10cm_Max] => 26.18
[T0_10cm_Min] => 15.01
[T1_1m_Avg] => 27.74
[T1_1m_Max] => 34.07
[T1_1m_Min] => 22.81
[T2_2m_Avg] => 31.33
[T2_2m_Max] => 37.32
[T2_2m_Min] => 25.14
)
)
Where each key will be a series or "line" to graph, for example all the keys "PTemp_C_Avg" that are in the array will be grouped in the same series and so on.
I would appreciate any suggestions you could give me to solve this problem and if you could give me an example I would be very helpful