<delect id="sj01t"></delect>
  1. <em id="sj01t"><label id="sj01t"></label></em>
  2. <div id="sj01t"></div>
    1. <em id="sj01t"></em>

            <div id="sj01t"></div>

            PHP實現股票趨勢圖和柱形圖

            時間:2025-10-29 09:20:15 php語言

            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;

              /pic/p>

              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; /pic/p>

              /pic/p>

              $wheres = "where stock_no = ".$id;

              /pic/p>

              if (isset($_GET['min'])) {

              $wheres .= " and `created` >= ".(int)$_GET['min'];

              }

              /pic/p>

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

              }

              /pic/p>

              $line2 = array(); /pic/p>

              $bar = array(); /pic/p>

              $times = array(); /pic/p>

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

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

              $bar[] = $values['volume'];

              /pic/p>

              if ($keys % 4 == 0) {

              $times[] = $values['created'];

              } else {

              $times[] = VOID;

              }

              endforeach;

              $l2counts = count($line2);

              $myData = new pData();

              /pic/p>

              if ($type == "line") {

              /pic/p>

              $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;

              /pic/p>

              $stock_name = "某某公司";

              /pic/p>

              $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;

              }

              /pic/p>

              $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);

              /pic/p>

              $myPicture->setFontProperties(array("FontName" => "fonts/en_us.ttf", "FontSize" => 6));

              /pic/p>

              /pic/p>

              /pic/p>

              /pic/p>

              $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,

              /pic/p>

              "GridTicks" => 3, /pic/p>

              "ManualScale" => $AxisBoundaries,

              );

              $myPicture->drawScale($Settings);

              /pic/p>

              /*

              $line_arr = array(

              "ForceColor" => TRUE,

              "ForceR" => 0,

              "ForceG" => 0,

              "ForceB" => 255);

              $myPicture->drawLineChart($line_arr); */

              $myPicture->drawLineChart();

              /pic/p>

              $myData->setSerieDrawable("Line1",FALSE);

              /pic/p>

              $area_arr = array(

              "ForceTransparency"=>15, /pic/p>

              );

              $myPicture->drawAreaChart($area_arr);

              /pic/p>

              if ($showtxt) {

              /pic/p>

              $myPicture->drawText(200,30,$stock_name,array("FontName"=>$ttf_path, "FontSize"=>11,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));

              /pic/p>

              $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);

              }

              /pic/p>

              } else {

              $myData->addPoints($bar, "Bar");

              $myData->setPalette("Bar",array("R"=>51,"G"=>114,"B"=>178)); /pic/p>

              $myData->addPoints($times, "Times");

              $myData->setSerieDescription("Times","Time");

              $myData->setAbscissa("Times");

              $myData->setXAxisDisplay(AXIS_FORMAT_TIME,"H:i");

              $myPicture = new pImage(480, 200, $myData);

              /pic/p>

              $myPicture->setFontProperties(array("FontName" => "fonts/en_us.ttf", "FontSize"=>6));

              $myPicture->Antialias = FALSE;

              $myPicture->setGraphArea(50,20,450,180);

              /pic/p>

              $scaleSettings = array(

              "Mode" => SCALE_MODE_START0,

              "GridR"=>200,

              "GridG"=>200,

              "GridB"=>200);

              $myPicture->drawScale($scaleSettings);

              /*

              $Palette = array();

              for ($i = 0; $i <= $l2counts; $i++) {

              $Palette[$i] = array("R"=>74,"G"=>114,"B"=>178,"Alpha"=>100);

              }

              /pic/p>

              /* 覆蓋畫板色

              $barSetting = array(

              "OverrideColors"=>$Palette,

              );

              $myPicture->drawBarChart($barSetting);

              */

              $myPicture->drawBarChart();

              /pic/p>

              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; /pic/p>

              foreach ($bar as $value) {

              $alls += $value;

              }

              $myData->setSerieDescription("Bar", $desc_tip[$lang]['bar'].$alls);

              $myPicture->drawLegend(300,9,$tips);

              }

              }

              $myPicture->stroke();

              /pic/p>

              /pic/p>

              /pic/p>

              ?>

            【PHP實現股票趨勢圖和柱形圖】相關文章:

            php實現編輯和保存文件的方法02-27

            php的curl實現get和post的代碼11-12

            PHP實現文件上傳和多文件上傳01-19

            php注冊和登錄界面的實現案例11-21

            實現PHP實現限制IP訪問02-23

            PHP就業趨勢201711-29

            Excel2010如何制作柱形圖01-10

            PHP中使用cURL實現Get和Post請求03-07

            PHP實現定時任務的幾種方式和詳解08-11

            <delect id="sj01t"></delect>
            1. <em id="sj01t"><label id="sj01t"></label></em>
            2. <div id="sj01t"></div>
              1. <em id="sj01t"></em>

                      <div id="sj01t"></div>
                      黄色视频在线观看