01.
<?php
02.
$conn
= mysqli_connect(
"localhost"
,
"root"
,
""
,
"test"
)
or
die
(
"Error: "
. mysqli_error(
$con
));
03.
04.
mysqli_query(
$conn
,
"SET NAMES 'utf8' "
);
05.
06.
$lineX
=
array
();
07.
$lineY
=
array
();
08.
$sql
=
"SELECT NAME,TimeE,Total,DateE FROM line WHERE DateE = '2019-03-29' AND NAME='EMPO1' ORDER BY TimeE ASC"
;
09.
10.
$result
= mysqli_query(
$conn
,
$sql
);
11.
while
(
$row
= mysqli_fetch_array(
$result
,MYSQLI_ASSOC)) {
12.
13.
array_push
(
$lineY
,
$row
[Total]);
14.
array_push
(
$lineX
,
$row
[TimeE]);
15.
}
16.
?>
17.
<!DOCTYPE HTML>
18.
<html>
19.
<head>
20.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
>
21.
<title>กราฟแสดงข้อมูลการทำงาน</title>
25.
<script>
26.
$(
function
() {
27.
$(
'#container'
).highcharts({
28.
chart: {
29.
type:
'line'
30.
},
31.
title: {
32.
text:
'แสดงกราฟชั่วโมงทำงาน '
33.
},
34.
subtitle: {
35.
text:
''
36.
},
37.
xAxis: {
38.
categories: [
'<?php echo implode("'
,
'", $lineX); ?>'
]
39.
},
40.
yAxis: {
41.
title: {
42.
text:
'จำนวนยอดผลิต'
43.
}
44.
},
45.
tooltip: {
46.
enabled: false,
47.
formatter:
function
() {
48.
return
'<b>'
+ this.series.name +
'</b><br/>'
+
49.
this.x +
': '
+ this.y ;
50.
}
51.
},
52.
legend: {
53.
layout:
'vertical'
,
54.
align:
'right'
,
55.
verticalAlign:
'top'
,
56.
x: -10,
57.
y: 100,
58.
borderWidth: 0
59.
},
60.
plotOptions: {
61.
line: {
62.
dataLabels: {
63.
enabled: true
64.
},
65.
enableMouseTracking: false
66.
}
67.
},
68.
series: [{
69.
name:
'จำนวน'
,
70.
data: [<?php
echo
implode(
','
,
$lineY
) ?>]
71.
}]
72.
});
73.
});
74.
</script>
75.
76.
</head>
77.
<body>
78.
79.
<div id=
"container"
style=
"min-width: 320px; height: 380px; margin: 0 auto"
></div>
80.
81.
</body>
82.
</html>