您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 沧州分类信息网,免费分类信息发布

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

2024/3/29 23:51:07发布32次查看
基于强大的pchart类库。
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` 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 = $func_name($stock_info['name']); $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 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)); //背景颜色 //$settings = array(startr=>219, startg=>231, startb=>139, endr=>1, endg=>138, endb=>68, alpha=>50); //$mypicture->drawgradientarea(0,0,480,300,direction_vertical,$settings);//画格子和标签 $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, //drawxlines => false, gridticks => 3, //格子密度 manualscale => $axisboundaries, ); $mypicture->drawscale($settings);//画线 /* $line_arr = array( forcecolor => true, forcer => 0, forceg => 0, forceb => 255); $mypicture->drawlinechart($line_arr); */ $mypicture->drawlinechart(); //设置line1为无效,再画底色 $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)); //设置line1为有效 $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); /* $palette = array(); for ($i = 0; $i 74,g=>114,b=>178,alpha=>100); } //$palette = array(0=>array(r=>74,g=>114,b=>178,alpha=>100)); /* 覆盖画板色 $barsetting = array( overridecolors=>$palette, ); $mypicture->drawbarchart($barsetting); */ $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();//$mypicture->autooutput(image.png);//保存日志//file_put_contents(log.txt, json_encode($mydata) . \n);?>
沧州分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录