찾다
php教程php手册php股票K线图生成代码

php股票K线图生成代码

Jun 13, 2016 am 09:48 AM
php암호사용하다그림성취하다생성하다그림프로그램재고디자인적 사고첫 번째

此程序实现php画柱状图 //它的设计思想是:首先以用imagecreate()来生成一个空白图形;其程序实现如下: //需要两种不同的颜色,正数一个 负数一个 ,一个数据数组,$path为保存图片的地址

//此程序实现php画柱状图,开发股票网站的朋友经常会碰到在生成k线图片,现在我们来看看一款利用php根据数组数据生成k线图片。
//它的设计思想是:首先以用imagecreate()来生成一个空白图形;其程序实现如下:
//需要两种不同的颜色,正数一个 负数一个 ,一个数据数组,$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 = "中国联通(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)
{
 //创建新空白图形
 //箭头50像素,内容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);//图表字体的大小
 
 //取得最大的数据
 $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,'华南财经网');
 //画坐标
 //坐标颜色为黑色,先画坐标,再画箭头
 $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);
 }//画图函数结束
//输出生成的图片
/*

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,'教科书大阿斯顿即可');
?>

本站原创教程,转载注明来源于http://www.bKjia.c0m/phper/php.html 否则必究

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25 : Myrise에서 모든 것을 잠금 해제하는 방법
4 몇 주 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

맨티스BT

맨티스BT

Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

MinGW - Windows용 미니멀리스트 GNU

MinGW - Windows용 미니멀리스트 GNU

이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

ZendStudio 13.5.1 맥

ZendStudio 13.5.1 맥

강력한 PHP 통합 개발 환경

에디트플러스 중국어 크랙 버전

에디트플러스 중국어 크랙 버전

작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경