I want to fill a graph with an array that I generate in PHP with a query in MYSQL but I do not know how to use it in the JS of the graph.
This PHP is where I generate the array:
$nmes = $mes;
$sumpt = 0;
$nestedData=array();
$sqlven = "SELECT * FROM registros WHERE MONTH(fecha_entrega) =".$row["mes"]." and estado = 'entregado'";
$queryven = mysqli_query($conexion, $sqlven) or die ("Error con la consulta");
while($rowven = mysqli_fetch_array($queryven)){
$summ3= $summ3 + $rowven["m3"];
$sumpt = $sumpt + $rowven["pu"] * $rowven["m3"];
}
$nestedData["mes"] = $nmes;
$nestedData["sumpt"] = $sumpt;
$data[] = $nestedData;
}
And the arrangement he gives me is this:
[
{
mes: "Junio",
sumpt: 446131
},
{
mes: "Julio",
sumpt: 907135.8
},
{
mes: "Agosto",
sumpt: 1156675
},
{
mes: "Septiembre",
sumpt: 366161
},
{
mes: "Octubre",
sumpt: 1245362.5
},
{
mes: "Noviembre",
sumpt: 854915
},
{
mes: "Diciembre",
sumpt: 161905
}
]
And here is where I want to insert it:
var areaChartData = {
labels : ["Aqui irian los datos"],
datasets: [
{
label : 'Electronics',
fillColor : 'rgba(210, 214, 222, 1)',
strokeColor : 'rgba(210, 214, 222, 1)',
pointColor : 'rgba(210, 214, 222, 1)',
pointStrokeColor : '#c1c7d1',
pointHighlightFill : '#fff',
pointHighlightStroke: 'rgba(220,220,220,1)',
data : ["Aqui irian los datos"]
}
]
}
Thank you in advance for your answers.