<?php
include
"libs/pData.class.php"
;
include
"libs/pDraw.class.php"
;
include
"libs/pImage.class.php"
;
include
"database.php"
;
include
"libs/convert.php"
;
date_default_timezone_set(
'Asia/Shanghai'
);
$type
= isset(
$_GET
[
'type'
]) ?
$_GET
[
'type'
] :
'line'
;
$showtxt
= (isset(
$_GET
[
'txt'
]) && (
$_GET
[
'txt'
] == 1)) ? true : false;
if
(isset(
$_GET
[
'lang'
])) {
$lang
=
$_GET
[
'lang'
] ==
'cn'
?
'cn'
:
'hk'
;
}
else
{
$lang
=
'hk'
;
}
$desc_tip
=
array
(
'hk'
=>
array
(
'line'
=>
array
(
"昨日收盤價"
,
"股價"
),
'bar'
=>
"總成交量:"
),
'cn'
=>
array
(
'line'
=>
array
(
"昨日收盘价"
,
"股价"
),
'bar'
=>
"总成交量:"
)
);
$id
= isset(
$_GET
[
'id'
]) ? (int)
$_GET
[
'id'
] : 1;
$wheres
=
"where stock_no = "
.
$id
;
if
(isset(
$_GET
[
'min'
])) {
$wheres
.=
" and `created` >= "
.(int)
$_GET
[
'min'
];
}
if
(isset(
$_GET
[
'max'
])) {
$wheres
.=
" and `created` <= "
.(int)
$_GET
[
'max'
];
}
$wheres
.=
" order by created"
;
$sth
=
$dbh
->prepare(
"SELECT * FROM $tb_name "
.
$wheres
);
$sth
->execute();
$results
=
$sth
->fetchAll(PDO::FETCH_ASSOC);
if
(
$lang
==
'hk'
) {
$ttf_path
=
"fonts/zh_hk.ttc"
;
}
else
{
$ttf_path
=
"fonts/zh_cn.ttf"
;
}
$line2
=
array
();
$bar
=
array
();
$times
=
array
();
foreach
(
$results
as
$keys
=>
$values
) :
$line2
[] =
$values
[
'current_price'
];
$bar
[] =
$values
[
'volume'
];
if
(
$keys
% 4 == 0) {
$times
[] =
$values
[
'created'
];
}
else
{
$times
[] = VOID;
}
endforeach
;
$l2counts
=
count
(
$line2
);
$myData
=
new
pData();
if
(
$type
==
"line"
) {
$stock_sth
=
$dbh
->prepare(
"SELECT `name` FROM `tbl_stock` WHERE `code` = {$id}"
);
$stock_sth
->execute();
$stock_info
=
$stock_sth
->fetch(PDO::FETCH_ASSOC);
$func_name
=
"zhconversion_"
.
$lang
;
$stock_name
=
"某某公司"
;
$sql
=
"SELECT MIN(`current_price`) xiao, MAX(`current_price`) da FROM $tb_name $wheres"
;
foreach
(
$dbh
->query(
$sql
, PDO::FETCH_ASSOC)
as
$row
) {
$bottom
= (int)
$row
[
'xiao'
] - 2;
$top
= (int)
$row
[
'da'
] + 2;
}
$l1s
=
array
();
for
(
$i
= 1;
$i
<=
$l2counts
;
$i
++) {
$l1s
[] = 130;
}
$myData
->addPoints(
$l1s
,
"Line1"
);
$myData
->addPoints(
$line2
,
"Line2"
);
$myData
->setPalette(
"Line1"
,
array
(
"R"
=>51,
"G"
=>114,
"B"
=>178));
$myData
->setPalette(
"Line2"
,
array
(
"R"
=>0,
"G"
=>255,
"B"
=>0));
$myData
->setAxisPosition(0, AXIS_POSITION_RIGHT);
$myData
->addPoints(
$times
,
"Times"
);
$myData
->setSerieDescription(
"Times"
,
"Time"
);
$myData
->setAbscissa(
"Times"
);
$myData
->setXAxisDisplay(AXIS_FORMAT_TIME,
"H:i"
);
$myPicture
=
new
pImage(480, 300,
$myData
);
$myPicture
->setFontProperties(
array
(
"FontName"
=>
"fonts/en_us.ttf"
,
"FontSize"
=> 6));
$myPicture
->setGraphArea(10, 40, 440, 260);
$AxisBoundaries
=
array
(0 =>
array
(
"Min"
=>
$bottom
,
"Max"
=>
$top
));
$Settings
=
array
(
"Mode"
=> SCALE_MODE_MANUAL,
"GridR"
=> 200,
"GridG"
=> 200,
"GridB"
=> 200,
"XMargin"
=> 0,
"YMargin"
=> 0,
"GridTicks"
=> 3,
"ManualScale"
=>
$AxisBoundaries
,
);
$myPicture
->drawScale(
$Settings
);
$myPicture
->drawLineChart();
$myData
->setSerieDrawable(
"Line1"
,FALSE);
$area_arr
=
array
(
"ForceTransparency"
=>15,
);
$myPicture
->drawAreaChart(
$area_arr
);
if
(
$showtxt
) {
$myPicture
->drawText(200,30,
$stock_name
,
array
(
"FontName"
=>
$ttf_path
,
"FontSize"
=>11,
"Align"
=>TEXT_ALIGN_BOTTOMMIDDLE));
$myData
->setSerieDrawable(
"Line1"
,TRUE);
$myData
->setSerieDescription(
"Line1"
,
$desc_tip
[
$lang
][
'line'
][0]);
$myData
->setSerieDescription(
"Line2"
,
$desc_tip
[
$lang
][
'line'
][1]);
$myPicture
->setFontProperties(
array
(
"FontName"
=>
$ttf_path
,
"FontSize"
=>8));
$tips
=
array
(
"Style"
=>LEGEND_NOBORDER,
"Mode"
=>LEGEND_HORIZONTAL,
"FontR"
=>0,
"FontG"
=>0,
"FontB"
=>0,
);
$myPicture
->drawLegend(20,26,
$tips
);
}
}
else
{
$myData
->addPoints(
$bar
,
"Bar"
);
$myData
->setPalette(
"Bar"
,
array
(
"R"
=>51,
"G"
=>114,
"B"
=>178));
$myData
->addPoints(
$times
,
"Times"
);
$myData
->setSerieDescription(
"Times"
,
"Time"
);
$myData
->setAbscissa(
"Times"
);
$myData
->setXAxisDisplay(AXIS_FORMAT_TIME,
"H:i"
);
$myPicture
=
new
pImage(480, 200,
$myData
);
$myPicture
->setFontProperties(
array
(
"FontName"
=>
"fonts/en_us.ttf"
,
"FontSize"
=>6));
$myPicture
->Antialias = FALSE;
$myPicture
->setGraphArea(50,20,450,180);
$scaleSettings
=
array
(
"Mode"
=> SCALE_MODE_START0,
"GridR"
=>200,
"GridG"
=>200,
"GridB"
=>200);
$myPicture
->drawScale(
$scaleSettings
);
$myPicture
->drawBarChart();
if
(
$showtxt
) {
$tips
=
array
(
"Style"
=>LEGEND_NOBORDER,
"Mode"
=>LEGEND_HORIZONTAL,
"FontR"
=>0,
"FontG"
=>0,
"FontB"
=>0,
);
$myPicture
->setFontProperties(
array
(
"FontName"
=>
$ttf_path
,
"FontSize"
=>9));
$alls
= 0;
foreach
(
$bar
as
$value
) {
$alls
+=
$value
;
}
$myData
->setSerieDescription(
"Bar"
,
$desc_tip
[
$lang
][
'bar'
].
$alls
);
$myPicture
->drawLegend(300,9,
$tips
);
}
}
$myPicture
->stroke();
?>