PHP实现股票趋势图和柱形图

来源:文书网 2.24W

文章主要介绍了PHP实现股票趋势图和柱形图,本文效果基于pchart类库实现,给出实现代码和效果图,需要的`朋友可以参考下。

PHP实现股票趋势图和柱形图

  基于强大的pchart类库。  <?php

/*

* 股票趋势图和柱形图

* @author: Skiychan >

* @created: 02/05/2015

*/

include "libs/";

include "libs/";

include "libs/";

include "";

include "libs/";

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_";

} else {

$ttf_path = "fonts/zh_";

}

//初始化

$line2 = array(); //股价

$bar = array(); //成交量

$times = array(); //时间

foreach ($results as $keys => $values) :

$line2[] = $values['current_price'];

热门标签