PHP实现股票趋势图和柱形图实现股票趋势图和柱形图
主要介绍了PHP实现股票趋势图和柱形图,本文效果基于pchart类库实现,给出实现代码和效果图,需要的朋友可以
参考下
基于强大的pchart类库。
<?php
/*
* 股票趋势图和柱形图
* @author: Skiychan <developer@zzzzy.com>
* @created: 02/05/2015
*/
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');
/*
* @param type line/other 趋势图/柱形图 默认趋势图
* @param txt 1/other 显示/不显示 提示文字 默认不显示
* @param lang hk/cn 繁体中文/简体中文 默认繁体
* @param id int 股票编号 必填
* @param min int 最小时间 默认无
* @param max int 最大时间 默认无
*/
$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";
}