php股票K線圖生成代碼
Jun 13, 2016 am 09:48 AM此程序?qū)崿F(xiàn)php畫柱狀圖 //它的設(shè)計思想是:首先以用imagecreate()來生成一個空白圖形;其程序?qū)崿F(xiàn)如下: //需要兩種不同的顏色,正數(shù)一個 負數(shù)一個 ,一個數(shù)據(jù)數(shù)組,$path為保存圖片的地址
//此程序?qū)崿F(xiàn)php畫柱狀圖,開發(fā)股票網(wǎng)站的朋友經(jīng)常會碰到在生成k線圖片,現(xiàn)在我們來看看一款利用php根據(jù)數(shù)組數(shù)據(jù)生成k線圖片。
//它的設(shè)計思想是:首先以用imagecreate()來生成一個空白圖形;其程序?qū)崿F(xiàn)如下:
//需要兩種不同的顏色,正數(shù)一個 負數(shù)一個 ,一個數(shù)據(jù)數(shù)組,$path為保存圖片的地址
$data = array ("-1174.58","-1865.41","1961.24","-1174.58","-1865.41","1961.24","-1174.58","-1865.41","1961.24","-1174.58","-1865.41","1961.24","-1174.58","-1865.41","1961.24","-1174.58","-1865.41","1961.24","-1174.58","-1865.41","1961.24","-1174.58","-1865.41","1961.24","-1174.58","-1865.41","1961.24","-1174.58","-1865.41","1961.24");
$colors = array (array (255,0,0 ),array (0,255,0 ) );
$path = "gg15_600050.gif";
$title = "中國聯(lián)通(600050)30日資金進出";
$date = array ("2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00","2010-05-20 00:00:00");
$hai = array(7203,6037,1931,9605,7405,8855,228,7771,8671,8791,1290,426,3265,4298,4809,3350,8204,8682,5523,7569,5853,593,3124,9062,3329,3236,2252,8756,2796,5164,2599,2630,1470,9779,8805,1512,1517,5635,760,1380,152,6035,2905,3163,9443,9432,5031,2838,6802,9330,1878,1333,4297,4180,3037,4527,9043,7287,3248,3448,3405,7204,2203,3974,4399,7333,4541,7033,4292,6128,9955,8603,297,6992,3282,9612,4483,8379,4016,6038,4163,3789,6896,8710,1502,1579,1712,3705,3619,5150,3007,1853,2776,3056,569,9031,6092,8600,8941,6366,5829,433,8011,9637,9106,1761,2422,9873,8186,1136,1763,3050,285,1962,775,9900,7371,2691,9051,6596,6858,6726,1527,3970,910,2621,7598,7899,6546,3678,2202,9411,6129,8352,4830,4484,6776,243,323,3946,751,7508,8173,3776,5071,3847,3318,4901,2102,7516,5251,3299,8859,2114,8711,9800,7707,5898,3489,580,5763,2470,4126,6269,5191,182,412,3043,3208,2438,6889,1732,1979,7692,3445,8214,8620,9446,4624,3615,5496,6152,213,3715,9623,1215,4757,9443,3366,2988,8043,6874,3742,4974,4812,6839,3016,5625,4656,5315,8303,8346,2315,3230,1969,1688,7381,6463,1030,8856,4691,6042,7652,8502,3839,7844,9149,4029,9465,2897,7688,3791,1458,6981,484,1290,4261,1222,9503,4881,7663,1399,2260,8066,6405,8442,722,9297,177,8426,2103,2078,3521,2280,8570,4663,6227,5784,7438,654,3036,9965,872,8306,3537,899,5888,1319,2472,9218,4853,7849,9433,1196,4880,1597,9258,7465,8138,817,1637,4201,1939,8914,1114,2232,8251,4538,7378,7438,4489,993,5269,944,2718,6633,4378,8431,155,5061,9347,1125,8865,4629,9965,4706,6263,8742,971,301);
draw(600,300,$data,$colors,$path,$title,$date);
function draw($w,$h,$data,$colors,$path,$title,$date)
{
?//創(chuàng)建新空白圖形
?//箭頭50像素,內(nèi)容400*300
?$width = $w;
?$height = $h;
?//取得左下角的坐標點,左邊50像素和最下邊50像素用于寫標尺
?$l_b_x = 50;
?$l_b_y = $height/2;
?
?$chartfont = 2; //圖表字體
?$font = 'c:/windows/fonts/simsun.ttc';//支持漢字的字體
?$chartfontheight = imagefontheight($chartfont);//圖表字體的大小
?
?//取得最大的數(shù)據(jù)
?$max = abs(max($data));
?$max = $max>abs(min($data))?$max:abs(min($data));
?$image = imagecreate($width,$height);
?
?//填充背景為白色
?$color_white = imagecolorallocate($image, 0xff, 0xff, 0xff);//白色
?$color_diwen = imagecolorallocate($image,0xd8,0xd8,0xd8);//暗灰色
?imagefill($image,0,0,$color_white);
?//寫入logo
?imagettftext($image,20,0,$l_b_x+20,45,$color_diwen,$font,'華南財經(jīng)網(wǎng)');
?//畫坐標
?//坐標顏色為黑色,先畫坐標,再畫箭頭
?$black_color = imagecolorallocate($image,0x00,0x00,0x00);
?imageline($image,$l_b_x,$l_b_y,$l_b_x,10,$black_color);
?imageline($image,$l_b_x,$l_b_y,$width-10,$l_b_y,$black_color);
?//箭頭
?imageline($image,$l_b_x,10,$l_b_x-3,14,$black_color);
?imageline($image,$l_b_x,10,$l_b_x+3,14,$black_color);
?imageline($image,$width-10,$l_b_y,$width-13,$l_b_y-3,$black_color);
?imageline($image,$width-10,$l_b_y,$width-13,$l_b_y+3,$black_color);
?//畫底紋,灰色;畫20條底紋;虛線
?$pit = floor(($l_b_y-50)/10);//每一段的高度
?$pit_x = floor(($width-$l_b_x-30)/count($data));//每一段的寬度
?//計算單位
?$x_max = $max;
?$flag_danwei = 0;
?while($x_max> 1000 )
?{
??$x_max /= 100;
??$flag_danwei++;
?}
?switch($flag_danwei)
?{
?//?case 0:$danwei = '(元)';break;
??case 0:$danwei = '(萬)';break;
??case 1:$danwei = '(百萬)';break;
??case 2:$danwei = '(億)';break;
??case 3:$danwei = '(百億)';break;
?}
?for($i=1;$i ?{
??imageline($image,$l_b_x+1,$l_b_y-$i*$pit,$width-15,$l_b_y-$i*$pit,$color_diwen);
??//從坐標的值
??$v_v = number_format(($max/(10*pow(100,$flag_danwei))*$i),2);
??$v_v = substr($v_v,0,5);
??imagestring($image,
?????$chartfont,
?????$l_b_x-40,
?????$l_b_y-$i*$pit-10,
?????$v_v,
?????$black_color);
?}
?//原點坐標
?imagestring($image,
????$chartfont,
????$l_b_x-20,
????$l_b_y-10,
????0,
????$black_color);
?//寫入漢字,單位 和標題
?imagettftext($image, 10,0,$l_b_x-45,20,$black_color,$font,$danwei);
?//imagettftext($image, 11,0,$width/2-70,$l_b_y+20,$black_color, $font,$title);?//畫柱體,長方形,并著色
?$color_big = imagecolorallocate($image,$colors[0][0],$colors[0][1],$colors[0][2]);
?$color_small = imagecolorallocate($image,$colors[1][0],$colors[1][1],$colors[1][2]);
?for($j=0;$j?{
??$d_h = floor(abs($data[$j]/$max*10*$pit));//柱體高度
??$current_date = substr($date[$j],5,5);
?//?$current_date .= substr($date[$j],8,2);
??imagerectangle($image,
?????$l_b_x+$j*$pit_x+1,
?????$l_b_y,
?????$l_b_x+($j+1)*$pit_x-2,
?????$l_b_y-$d_h,
?????$black_color);
??//為矩形著色
??$current_color = $data[$j]>0?$color_big:$color_small;
??imagefilltoborder($image,
????$l_b_x+$j*$pit_x+1 + floor($pit_x/2),
????$l_b_y-floor($d_h/2),
????$black_color,
????$current_color);
??//寫入日期
??/*imagestring($image,
????$chartfont,
????$l_b_x+$j*$pit_x,
????$l_b_y+2,
????$current_date,
????$black_color);*/
??imagettftext($image,8,90,$l_b_x+$j*$pit_x+10,$l_b_y-$d_h,$black_color,$font,$current_date);
?}?
?if($path !="")
??imagegif($image,$path);
?else imagegif($image);
?imagedestroy($image);
?}//畫圖函數(shù)結(jié)束
//輸出生成的圖片
/*header("content-type: image/gif");
$my_colors[] = array(0xff,0x00,0x00);
$my_colors[] = array(0x00,0xff,0x00);
draw(600,400,array(1066565650,-40345340,50343433440,1834340,50343230,-8023454230,600,7232323300,-836),$my_colors,0,'教科書大阿斯頓即可');*/
//draw(600,400,array(1066,-4040,5040,1840,5030,-8230,600,7232,-836),$my_colors,0,'教科書大阿斯頓即可');
?>
本站原創(chuàng)教程,轉(zhuǎn)載注明來源于http://www.bKjia.c0m/phper/php.html 否則必究

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

The core method of building social sharing functions in PHP is to dynamically generate sharing links that meet the requirements of each platform. 1. First get the current page or specified URL and article information; 2. Use urlencode to encode the parameters; 3. Splice and generate sharing links according to the protocols of each platform; 4. Display links on the front end for users to click and share; 5. Dynamically generate OG tags on the page to optimize sharing content display; 6. Be sure to escape user input to prevent XSS attacks. This method does not require complex authentication, has low maintenance costs, and is suitable for most content sharing needs.

User voice input is captured and sent to the PHP backend through the MediaRecorder API of the front-end JavaScript; 2. PHP saves the audio as a temporary file and calls STTAPI (such as Google or Baidu voice recognition) to convert it into text; 3. PHP sends the text to an AI service (such as OpenAIGPT) to obtain intelligent reply; 4. PHP then calls TTSAPI (such as Baidu or Google voice synthesis) to convert the reply to a voice file; 5. PHP streams the voice file back to the front-end to play, completing interaction. The entire process is dominated by PHP to ensure seamless connection between all links.

To realize text error correction and syntax optimization with AI, you need to follow the following steps: 1. Select a suitable AI model or API, such as Baidu, Tencent API or open source NLP library; 2. Call the API through PHP's curl or Guzzle and process the return results; 3. Display error correction information in the application and allow users to choose whether to adopt it; 4. Use php-l and PHP_CodeSniffer for syntax detection and code optimization; 5. Continuously collect feedback and update the model or rules to improve the effect. When choosing AIAPI, focus on evaluating accuracy, response speed, price and support for PHP. Code optimization should follow PSR specifications, use cache reasonably, avoid circular queries, review code regularly, and use X

1. Maximizing the commercial value of the comment system requires combining native advertising precise delivery, user paid value-added services (such as uploading pictures, top-up comments), influence incentive mechanism based on comment quality, and compliance anonymous data insight monetization; 2. The audit strategy should adopt a combination of pre-audit dynamic keyword filtering and user reporting mechanisms, supplemented by comment quality rating to achieve content hierarchical exposure; 3. Anti-brushing requires the construction of multi-layer defense: reCAPTCHAv3 sensorless verification, Honeypot honeypot field recognition robot, IP and timestamp frequency limit prevents watering, and content pattern recognition marks suspicious comments, and continuously iterate to deal with attacks.

PHP does not directly perform AI image processing, but integrates through APIs, because it is good at web development rather than computing-intensive tasks. API integration can achieve professional division of labor, reduce costs, and improve efficiency; 2. Integrating key technologies include using Guzzle or cURL to send HTTP requests, JSON data encoding and decoding, API key security authentication, asynchronous queue processing time-consuming tasks, robust error handling and retry mechanism, image storage and display; 3. Common challenges include API cost out of control, uncontrollable generation results, poor user experience, security risks and difficult data management. The response strategies are setting user quotas and caches, providing propt guidance and multi-picture selection, asynchronous notifications and progress prompts, key environment variable storage and content audit, and cloud storage.

PHP ensures inventory deduction atomicity through database transactions and FORUPDATE row locks to prevent high concurrent overselling; 2. Multi-platform inventory consistency depends on centralized management and event-driven synchronization, combining API/Webhook notifications and message queues to ensure reliable data transmission; 3. The alarm mechanism should set low inventory, zero/negative inventory, unsalable sales, replenishment cycles and abnormal fluctuations strategies in different scenarios, and select DingTalk, SMS or Email Responsible Persons according to the urgency, and the alarm information must be complete and clear to achieve business adaptation and rapid response.

PHPisstillrelevantinmodernenterpriseenvironments.1.ModernPHP(7.xand8.x)offersperformancegains,stricttyping,JITcompilation,andmodernsyntax,makingitsuitableforlarge-scaleapplications.2.PHPintegrateseffectivelyinhybridarchitectures,servingasanAPIgateway

The core role of Homebrew in the construction of Mac environment is to simplify software installation and management. 1. Homebrew automatically handles dependencies and encapsulates complex compilation and installation processes into simple commands; 2. Provides a unified software package ecosystem to ensure the standardization of software installation location and configuration; 3. Integrates service management functions, and can easily start and stop services through brewservices; 4. Convenient software upgrade and maintenance, and improves system security and functionality.
