Good morning, I've been trying to get the chart.js graph for two weeks to grab the data from the database and display it in real time.
Follow my database.
CREATE TABLE 'tab_clientes' (
'id' int(11) NOT NULL,
'data_nascimento' date DEFAULT NULL,
'line' varchar(220) NOT NULL,
'model' varchar(220) NOT NULL,
'wo' varchar(220) NOT NULL,
'tool' varchar(220) NOT NULL,
'detection_point' varchar(220) NOT NULL,
'defect_content' varchar(220) NOT NULL,
'causes' varchar(220) NOT NULL,
'owner' varchar(220) NOT NULL,
'qty' varchar(220) NOT NULL,
'ppm' varchar(220) NOT NULL,
'action' varchar(220) NOT NULL,
'symptom' varchar(220) NOT NULL,
'status' varchar(10) DEFAULT NULL,
'foto' varchar(200) DEFAULT NULL,
'data_cadastro' timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
'data_alteracao' timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
The Symptom column of the Leakage or Function response would like to count each and give the result per week.
I tried this way ... but I can not divide the days of the week in relation to the selected date.
<?php
// Consultar dados
$dados = array();
$sql = "SELECT symptom, COUNT(*) as data_nascimento FROM tab_clientes WHERE data_nascimento BETWEEN '2018-11-28' AND '2018-11-29' GROUP BY symptom";
$pdo = new PDO('mysql:host=localhost;dbname=db_blog', 'root', '');
$stmt = $pdo->query($sql);
while ($obj = $stmt->fetchObject()) {
switch ($obj->symptom) {
case 'Leakage':
$dados['Leakage'] = $obj->data_nascimento;
break;
case 'Function':
$dados['Function'] = $obj->data_nascimento;
break;
}
}?>
<script>
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: ["W", "Monday", "Tuesday", "Wednesday", "W48", "W49", "W50"],
datasets: [{
label: "Leakeage",
data: [<?php echo $dados['Leakage']?>, <?php echo $dados['Leakage']?>, <?php echo $dados['Leakage']?>, <?php echo $dados['Leakage']?>, <?php echo $dados['Leakage']?>, <?php echo $dados['Leakage']?>, <?php echo $dados['Leakage']?>],
lineTension: 0,
backgroundColor: 'transparent',
borderColor: '#007bff',
borderWidth: 4,
pointBackgroundColor: '#007bff'
},{
label: "Function",
data: [<?php echo $dados['Function']?>, <?php echo $dados['Function']?>, <?php echo $dados['Function']?>, <?php echo $dados['Function']?>, <?php echo $dados['Function']?>, <?php echo $dados['Function']?>, <?php echo $dados['Function']?>],
lineTension: 0,
backgroundColor: 'transparent',
borderColor: '#7bff00',
borderWidth: 4,
pointBackgroundColor: '#7bff00'
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: false
}
}]
},
legend: {
display: false,
}
}
});
</script>
If anyone can help me. Thank you very much !!!