Live, I have 2 graphs and wanted to bring them values from the database so I use php and bring the values with Json as follows:
$pe= array();
$pe['fechados'] = $total_fechados;
$pe['aguarda'] = $total_aguardar_resposta;
$pe['analise'] = $total_analise;
$pe['reparacao'] = $total_reparacao;
echo json_encode($pe);
After this, I searched the net and found several things and implemented this
<script>
$(document).ready(function(){
/* call the php that has the php array which is json_encoded */
$.getJSON('../includes/grafico_pedidos.php', function(data) {
/* data will hold the php array as a javascript object */
$.each(data, function(key, val) {
var f = val.fechados;
var ag = val.aguarda;
var an = val.analise;
var r = val.reparacao;
});
});
});
var pieData1 = [
{ value: f, color:"#F7464A", highlight: "#FF5A5E", label: "Fechados"},
{ value: ag, color: "#46BFBD", highlight: "#5AD3D1", label: "Aguarda Resposta"},
{ value: an, color: "#FDB45C", highlight: "#FFC870", label: "Em Análise"},
{ value: r, color: "#949FB1", highlight: "#A8B3C5", label: "Em Reparação"},
{ value: 120, color: "#4D5360", highlight: "#616774", label: "Dark Grey"}];
var doughnutData = [
{ value: 300, color:"#F7464A", highlight: "#FF5A5E", label: "Red"},
{ value: 50, color: "#46BFBD", highlight: "#5AD3D1", label: "Green"},
{ value: 100, color: "#FDB45C", highlight: "#FFC870", label: "Yellow"},
{ value: 40, color: "#949FB1", highlight: "#A8B3C5", label: "Grey"},
{ value: 120, color: "#4D5360", highlight: "#616774", label: "Dark Grey"} ];
var ctx = document.getElementById("chart-area").getContext("2d");
var myDoughnut = new Chart(ctx).Doughnut(doughnutData, {responsive : true});
var ctx1 = document.getElementById("pie").getContext("2d");
var myPie = new Chart(ctx1).Pie(pieData1, {responsive : true});
</script>
But I wanted to highlight the part where I get the data from the php file. My question is how to receive and put them in the values of the chart