01.
<?php
02.
03.
$host
=
"localhost"
;
04.
$user
=
"root"
;
05.
$pwd
=
"123456"
;
06.
$db
=
"highcharts"
;
07.
global
$link
;
08.
$link
= mysql_connect(
$host
,
$user
,
$pwd
)
or
die
(
"Could not connect to MySQL"
);
09.
mysql_query(
"SET NAMES UTF8"
,
$link
);
10.
mysql_select_db(
$db
,
$link
)
or
die
(
"Could not select $db database"
);
11.
12.
$monthx
=
array
();
13.
$y2556
=
array
();
14.
15.
$sql
=
"SELECT line.`month`, line.`value` FROM line"
;
16.
17.
$result
= mysql_query(
$sql
);
18.
while
(
$row
=mysql_fetch_array(
$result
)) {
19.
20.
array_push
(
$y2556
,
$row
[value]);
21.
array_push
(
$monthx
,
$row
[month]);
22.
}
23.
?>
24.
25.
<script>
26.
$(
function
() {
27.
$(
'#container'
).highcharts({
28.
chart: {
29.
type:
'column'
30.
},
31.
title: {
32.
text:
'จำนวนลูกค้า'
33.
},
34.
subtitle: {
35.
text:
''
36.
},
37.
xAxis: {
38.
categories: [glow=red][
'<?= implode("'
,
'", $monthx); //นำตัวแปร array แกน x มาใส่ ในที่นี้คือ เดือน?>'
][/glow]
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:
'พ.ศ.2556'
,
70.
data: [glow=red][<?= implode(
','
,
$y2556
)
71.
}]
72.
});
73.
});
74.
</script>