|
|
|
สอบถามผู้รู้หน่อย ครับ......ดึกข้อมูล ในฐานมาแสดงเป็น กราฟ ครับ |
|
|
|
|
|
|
|
Code (PHP)
<!-- Connect Database --> ตอนดึงข้อมูลจากฐานข้อมูล
<?php
include("_stk_connect.php");
$sql = "SELECT ItemName, Value FROM `tb_items` ORDER BY Value DESC LIMIT 15" ;
$result = mysqli_query($conn,$sql);
if(mysqli_num_rows( $result)>0 ) {
while($row = mysqli_fetch_assoc($result)) {
$items[] = $row['ItemCode'];
$lebels[] = $row['ItemName'];
$data[] = $row['Value'];
}
}
?>
จับมายัดใส่ในกราฟ ประมาณนี้นะครับ สามารถประยุกต์ใช้ได้กับทุกกราฟ
<script>
var chart = AmCharts.makeChart("chartdiv", {
"theme": "light",
"type": "serial",
"startDuration": 2,
"dataProvider": [{
"country": <?=json_encode($lebels[0])?>,
"visits": <?=json_encode($data[0], JSON_NUMERIC_CHECK);?>,
"color": "#FF0F00"
}, {
"country": <?=json_encode($lebels[1])?>,
"visits": <?=json_encode($data[1], JSON_NUMERIC_CHECK);?>,
"color": "#FF6600"
}, {
"country": <?=json_encode($lebels[2])?>,
"visits": <?=json_encode($data[2], JSON_NUMERIC_CHECK);?>,
"color": "#FF9E01"
}, {
"country": <?=json_encode($lebels[3])?>,
"visits": <?=json_encode($data[3], JSON_NUMERIC_CHECK);?>,
"color": "#FCD202"
}, {
"country": <?=json_encode($lebels[4])?>,
"visits": <?=json_encode($data[4], JSON_NUMERIC_CHECK);?>,
"color": "#F8FF01"
}, {
"country": <?=json_encode($lebels[5])?>,
"visits": <?=json_encode($data[5], JSON_NUMERIC_CHECK);?>,
"color": "#B0DE09"
}, {
"country": <?=json_encode($lebels[6])?>,
"visits": <?=json_encode($data[6], JSON_NUMERIC_CHECK);?>,
"color": "#04D215"
}, {
"country": <?=json_encode($lebels[7])?>,
"visits": <?=json_encode($data[7], JSON_NUMERIC_CHECK);?>,
"color": "#0D8ECF"
}, {
"country": <?=json_encode($lebels[8])?>,
"visits": <?=json_encode($data[8], JSON_NUMERIC_CHECK);?>,
"color": "#0D52D1"
}, {
"country": <?=json_encode($lebels[9])?>,
"visits": <?=json_encode($data[9], JSON_NUMERIC_CHECK);?>,
"color": "#2A0CD0"
}, {
"country": <?=json_encode($lebels[10])?>,
"visits": <?=json_encode($data[10], JSON_NUMERIC_CHECK);?>,
"color": "#8A0CCF"
}],
"valueAxes": [{
"position": "left",
"axisAlpha":0,
"gridAlpha":0
}],
"graphs": [{
"balloonText": "[[category]]: <b>[[value]]</b>",
"colorField": "color",
"fillAlphas": 0.85,
"lineAlpha": 0.1,
"type": "column",
"topRadius":1,
"valueField": "visits"
}],
"depth3D": 40,
"angle": 30,
"chartCursor": {
"categoryBalloonEnabled": false,
"cursorAlpha": 0,
"zoomable": false
},
"categoryField": "country",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha":0,
"gridAlpha":0
},
"export": {
"enabled": true
}
}, 0);
</script>
<!-- Chart code -->
|
|
|
|
|
Date :
2017-09-14 16:10:38 |
By :
joesky2409 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|