I just start with charjs and I need to print values from a database, at the moment I'm doing the exercise with numbers placed directly to the code, which does not work for me. AJAX:
$.ajax({
data: { "cc":3},
type: "POST",
url: "qgetdata.php",
success: function (data)
{
var ctx = document.getElementById("myChart").getContext("2d");
var lineChartData = data;
//alert(JSON.stringify(data));
var myLineChart = new Chart(ctx, {
type: 'line',
data: {
labels: ['lunes', 'martes', 'miercoles', 'jueves', 'viernes', 'Sabado', 'domingo'],
datasets: [
{
lineChartData
}]
}, options :{
}
});
}
});
PHP where I have the data that I want to draw on the graph:
$arrDatasets = array('label' => "elemento1",'fill' => "false", 'lineTension' => "0.1", 'pointBorderColor' => "rgba(75,192,192,1)", 'pointBorderWidth' => "3", 'pointHoverRadius' => "5", 'pointHoverBackgroundColor' => "rgba(220,220,220,1)", 'backgroundColor'=>"rgba(75,192,192,0.4)" , 'borderColor'=> "rgba(75,192,192,1)", 'spanGaps'=>"true", 'data' => array('28', '48', '40', '19', '86', '27', '90'));
echo (json_encode($arrDatasets));