วิธีการสร้างกราฟ High Chart 7.1.2 ใช้ภาษา PHP

jQuery & Ajax Knowledge ความรู้เกี่ยวกับ Javascript , jQuery และ Ajax

Moderator: mindphp, ผู้ดูแลกระดาน

Patipat
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 996
ลงทะเบียนเมื่อ: 10/06/2019 10:12 am

วิธีการสร้างกราฟ High Chart 7.1.2 ใช้ภาษา PHP

โพสต์ที่ยังไม่ได้อ่าน โดย Patipat »

แนะนำการสร้างกราฟในภาษา PHP โดยใช้ร่วมกับ js ทำความรู้จักกับ High Chart ทำงานกับ jqry
[attachment=6]Selection_921.png[/attachment]
ตัวอย่างของกราฟ High Chart มีหลากหลายรูปแบบสามารถเลือกใช้งานได้ ดูที่ลิงค์ด้านล่าง
https://www.highcharts.com/demo

1 . ขั้นตอนแรกให้เราเข้าไปที่เว็บไซต์ของ High chart > https://www.highcharts.com/blog/download/ แล้วทำการโหลด High chart 7.1.2 คลิกโหลด
[attachment=4]Selection_923.png[/attachment]

2. พอได้ไฟล์ของ High Chart แล้วให้ทำการแตกไฟล์แล้วย้ายไปยังโฟลเดอร์ Project ของเราที่ต้องการจะสร้างกราฟ
ตัวอย่างไฟล์ [attachment=3]Selection_924.png[/attachment]

3. ขั้นตอนต่อมา เปิดเข้าเว็บไปที่ https://www.highcharts.com/docs/getting ... stallation แล้วกด Installation
[attachment=5]Selection_922.png[/attachment]

4 .ต่อมาให้เราทำการก็อบปี้สคลิป ไปไว้ในโปรเจคที่เรากำลังจะทำกราฟ ในตัวอย่างจะมีทั้งสคิปที่เรียกมาจากเว็บ และ เรียกจากไฟล์ เลือกอย่างใดอย่างหนึ่งเท่านั้น
สคลิปนี้เรียกจากเว็บไซต์
[code]<script src="https://code.highcharts.com/highcharts.js"></script>[/code]

สคลิปนี้เรียกจาก ไฟล์ที่เราได้โหลดมาไว้ในโฟลเดอร์โปรเจคแล้ว
[code]<script src="/js/highcharts.js"></script>
[/code]


5. ทำการสร้าง tag Div เพื่อแสดงผลของกราฟบนเว็บเพจ ที่นี้ยกตัวอย่าง ขนาดของกราฟ กว้างเป็น 100% และสูงเพียง 600 px
[code]<div id="container" style="width:100%; height:600px;"></div>[/code]

6. เปิด สคลิป <script> </script> แล้วนำโค๊ดด้านล่างไปใส่ระหว่าง script ได้ยกตัวอย่างมาเช่น
[code]<script>
Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: 'ชื่อกราฟ'
},
xAxis: {
categories: ['คำอธิบายกราฟแนวนอน หรือ แกน X']
},
yAxis: {
min: 0,
title: {
text: 'คำอธิบายกราฟแนวตั้ง หรือ แกน Y'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
legend: {
align: 'right',
x: -30,
verticalAlign: 'top',
y: 25,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
headerFormat: '<b>{point.x}</b><br/>',
pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: [{
name: 'ชื่อข้อมูล1',
data: [ค่าของข้อมูล เป็นจำนวณตัวเลข]
}, {
name: 'ชื่อข้อมูล2',
data: [ค่าของข้อมูล เป็นจำนวณตัวเลข]
}]
});

</script>[/code]


ผลของกราฟก็จะแสดงดังนี้ครับ
[attachment=2]Selection_926.png[/attachment]

สามารถเลือกการใช้งานของกราฟได้หลายรูปแบบที่
https://www.highcharts.com/demo/column- ... nd-signika

ยกตัวอย่างเช่น เลือกกราฟชนิดนี้ แล้วกด View option
[attachment=1]Selection_927.png[/attachment]


เมื่อกด View Option แล้วจะได้โค๊ดของกราฟนี้มาแสดงผล แล้วสามรถนำไปประยุกต์ใช้งานได้
[attachment=0]Selection_928.png[/attachment]

สามารถศึกษาการเขียนโปรแกรม PHP ได้ที่ :arrow: :arrow: PHP พื้นฐาน
สอบถามการศึกษาข้อมูลเพิ่มเติมได้ที่ :arrow: ถามตอบ PHP
ขอบคุณข้อมูลจาก : https://www.highcharts.com/
แนบไฟล์
Selection_921.png
Selection_921.png (13.09 KiB) Viewed 2155 times
Selection_922.png
Selection_923.png
Selection_924.png
Selection_924.png (2.92 KiB) Viewed 2155 times
Selection_926.png
Selection_926.png (9.75 KiB) Viewed 2155 times
Selection_927.png
Selection_928.png
Selection_928.png (99.51 KiB) Viewed 2155 times
Kor ma di kub. :)
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 72