-2
I’m having trouble passing the $json[] array to Javascript, could someone help me.
<?php
include_once ('../conf/conexaoBanco.php');
$mensagem = "";
$stmt=$conectarBanco->prepare("SELECT * FROM orcamento");
$stmt->execute();
**$json = [];
while ($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
extract($row);
$json[] = (int)$quantidade;
}**
?>
<div class="container">
<div class="row">
<div class="col-sm-6">
<h2 class="sub-orcamento">Orçamento Mensal</h2>
<canvas class="line-chart"></canvas>
<!-- Chartjs -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<script>
var ctx = document.getElementsByClassName("line-chart");
//Type, Data e options
var chartGraph = new Chart(ctx, {
type: 'line',
data: {
labels: ["Jan","Fev","Mar","Abr","Mai","Jun","Jul","Ago","Set","Out","Nov","Dez"],
datasets: [{
label:"Orçados de <?php echo date('Y') ?>",
**data: {"<?php $quantidade ?>"},**
borderWidth: 6,
borderColor: 'rgba(77,166,253,0.8)'
}]
}
})
</script>
And why do you need to pass a PHP array to JSON? Are you familiar with the concepts of Client-Side and Server-Side? Could [Dit] your question and elaborate a [mcve]?
– Woss
Anderson Carlos Woss I need to pass this array to Javascript in order to generate a Chartsjs chart based on my database information. Yes I know the Client-Side and Server-Side concept, but if you have any better suggestions feel free to inform me because I’m here to learn
– Bruno Ferreira
Bruno, you say you have a problem passing a PHP array to JS, but you haven’t explained what the problem is. You just said you’re in trouble and put in a code. This doesn’t help much in getting a solution, because you don’t know what the problem is or the purpose of it.
– Sam
Sam the problem I’m having is that I don’t know how to pass the $json[] array to the date attribute of Chatsjs and I’ve tried it several ways searching the internet only that none gives me a solution that I can buy how to do this procedure
– Bruno Ferreira