 |
รบกวนช่วยสอน การนำตัวแปรจาก PHP ไปใช้ใน Javascript |
|
 |
|
|
 |
 |
|
สวัสดีค่ะ
จะรบกวนช่วยสอนการนำค่าจะ PHP ไปใส่ใน Javascript หน่อยค่ะ พอดีจะทำ chart ใช้ google chart แต่มีค่าที่ทำการคำนวณไว้แล้วใน ส่วนของ php ค่ะ
Code (PHP)
$summ1 = ($sumone / ($sumone + $sumzero))*100;
$summ0 = ($sumzero / ($sumone + $sumzero))*100;
Code (JavaScript)
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
// Load google charts
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
// Draw the chart and set the chart values
function drawChart() {
var data = google.visualization.arrayToDataTable([
['status', 'persent'],
['ผ่าน', 25.51],
['ไม่ผ่าน', 74.49]
]);
// Optional; add a title and set the width and height of the chart
var options = {'title':'ยอด 11 นาย, M (2), A (-), S (5), T (-), O (4)', 'width':550, 'height':400};
// Display the chart inside the <div> element with id="piechart"
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
ต้องการนำค่า $summ1 และ $summ0 มาใส่ใน Javascript ตรงค่า 25.51 และ 74.49 ค่ะ
ลองทำตามตัวอย่างจากหลายๆ ที่แต่ก็ยังไม่แสดงผลเลยค่ะ
รบกวนพี่ๆ ทีนะคะ
Tag : PHP, JavaScript
|
ประวัติการแก้ไข 2022-05-25 15:39:46
|
 |
 |
 |
 |
Date :
2022-05-25 15:38:56 |
By :
bananashy |
View :
630 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (JavaScript)
let sum0 = 25.51;
let sum1 = 74.49;
let array = [
['status', 'persent'],
];
array.push(['ผ่าน', sum0]);
array.push(['ไม่ผ่าน', sum1]);
google.visualization.arrayToDataTable(array);
console.log(array);
เปลี่ยนจากตัวเลขใน let sum0, letsum1 ไปเป็นค่าจาก php เอานะ
|
ประวัติการแก้ไข 2022-05-25 16:00:00
 |
 |
 |
 |
Date :
2022-05-25 15:59:30 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
var data = google.visualization.arrayToDataTable([
['status', 'persent'],
['ผ่าน', <?=$sum1?>],
['ไม่ผ่าน', <?$sum2?>]
]);
|
 |
 |
 |
 |
Date :
2022-05-25 16:00:24 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|