찾다
백엔드 개발PHP 튜토리얼php GD绘制24小时柱状图_PHP

80,250,430,134,35,60,233,90,263,225,120,59,151,677,340,221,550,300,229,97,230,123,133,87  一共24个数字 一个都不能少哦少了要出错 你可以修改函数判断一下
复制代码 代码如下:
/*   
24小时柱状图   
作者:taokey   
QQ:29611705   
*/   

function h24($str){    

        $hour = explode(",",$str);    
        $hmax = max($hour);    
        $ppix = 150/$hmax;    

        //计算柱状图高度    
        $h0 = 190-$hour[0]*$ppix;    
        $h1 = 190-$hour[1]*$ppix;    
        $h2 = 190-$hour[2]*$ppix;    
        $h3 = 190-$hour[3]*$ppix;    
        $h4 = 190-$hour[4]*$ppix;    
        $h5 = 190-$hour[5]*$ppix;    
        $h6 = 190-$hour[6]*$ppix;    
        $h7 = 190-$hour[7]*$ppix;    
        $h8 = 190-$hour[8]*$ppix;    
        $h9 = 190-$hour[9]*$ppix;    
        $h10 = 190-$hour[10]*$ppix;    
        $h11 = 190-$hour[11]*$ppix;    
        $h12 = 190-$hour[12]*$ppix;    
        $h13 = 190-$hour[13]*$ppix;    
        $h14 = 190-$hour[14]*$ppix;    
        $h15 = 190-$hour[15]*$ppix;    
        $h16 = 190-$hour[16]*$ppix;    
        $h17 = 190-$hour[17]*$ppix;    
        $h18 = 190-$hour[18]*$ppix;    
        $h19 = 190-$hour[19]*$ppix;    
        $h20 = 190-$hour[20]*$ppix;    
        $h21 = 190-$hour[21]*$ppix;    
        $h22 = 190-$hour[22]*$ppix;    
        $h23 = 190-$hour[23]*$ppix;    

        //创建一个img    
        $img = imagecreate(755,210);    
        //背景    
        $bgc = imagecolorallocate ($img, 245, 250, 254);    
        //黑色    
        $bc = imagecolorallocate($img,0,0,0);    
        //画竖轴    
        imageline($img,15,30,15,189, $bc);    
        //画横轴    
        imageline($img,15,190,750,190, $bc);    

        //画竖轴点    
        for($i=39,$j=10;$i                imageline($img,13,$i,15,$i, $bc);    
                imagestring($img,1,1,$i-4,$j."x", $bc);    
        }    

        //画横轴点    
        $t = true;    
        for($i=31,$j=29;$i                if($t){    
                        $x=$i;    
                        $t=false;    
                }else{    
                        $x=$i+1;    
                        $t=true;    
                }    
                imageline($img,$x,190,$x,192, $bc);    
        }    
        //竖轴标记    
        $x = ceil($hmax/10);    
        imagestring($img,2,10,15,"X=".$x,$bc);    
        //竖轴标记    

        //0点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,31,$h0,45,189,$color);    
        imagestring($img,1,31,$h0-10,$hour[0],$color);    
        imagechar($img,1,36,195,0,$bc);    

        //1点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,61,$h1,75,189,$color);    
        imagestring($img,1,61,$h1-10,$hour[1],$color);    
        imagechar($img,1,66,195,1,$bc);    

        //2点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,91,$h2,105,189,$color);    
        imagestring($img,1,91,$h2-10,$hour[2],$color);    
        imagechar($img,1,96,195,2,$bc);    

        //3点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,121,$h3,135,189,$color);    
        imagestring($img,1,121,$h3-10,$hour[3],$color);    
        imagechar($img,1,126,195,3,$bc);    

        //4点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,151,$h4,165,189,$color);    
        imagestring($img,1,151,$h4-10,$hour[4],$color);    
        imagechar($img,1,156,195,4,$bc);    

        //5点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,181,$h5,195,189,$color);    
        imagestring($img,1,181,$h5-10,$hour[5],$color);    
        imagechar($img,1,186,195,5,$bc);    

        //6点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,211,$h6,225,189,$color);    
        imagestring($img,1,211,$h6-10,$hour[6],$color);    
        imagechar($img,1,216,195,6,$bc);    

        //7点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,241,$h7,255,189,$color);    
        imagestring($img,1,241,$h7-10,$hour[7],$color);    
        imagechar($img,1,246,195,7,$bc);    

        //8点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,271,$h8,285,189,$color);    
        imagestring($img,1,271,$h8-10,$hour[8],$color);    
        imagechar($img,1,276,195,8,$bc);    

        //9点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,301,$h9,315,189,$color);    
        imagestring($img,1,301,$h9-10,$hour[9],$color);    
        imagechar($img,1,306,195,9,$bc);    

        //10点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,331,$h10,345,189,$color);    
        imagestring($img,1,331,$h10-10,$hour[10],$color);    
        imagestring($img,1,334,195,10,$bc);    

        //11点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,361,$h11,375,189,$color);    
        imagestring($img,1,361,$h11-10,$hour[11],$color);    
        imagestring($img,1,364,195,11,$bc);    

        //12点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,391,$h12,405,189,$color);    
        imagestring($img,1,391,$h12-10,$hour[12],$color);    
        imagestring($img,1,394,195,12,$bc);    

        //13点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,421,$h13,435,189,$color);    
        imagestring($img,1,421,$h13-10,$hour[13],$color);    
        imagestring($img,1,424,195,13,$bc);    

        //14点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,451,$h14,465,189,$color);    
        imagestring($img,1,451,$h14-10,$hour[14],$color);    
        imagestring($img,1,454,195,14,$bc);    

        //15点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,481,$h15,495,189,$color);    
        imagestring($img,1,481,$h15-10,$hour[15],$color);    
        imagestring($img,1,481,195,15,$bc);    

        //16点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,511,$h16,525,189,$color);    
        imagestring($img,1,511,$h16-10,$hour[16],$color);    
        imagestring($img,1,511,195,16,$bc);    

        //17点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,541,$h17,555,189,$color);    
        imagestring($img,1,541,$h17-10,$hour[17],$color);    
        imagestring($img,1,544,195,17,$bc);    

        //18点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,571,$h18,585,189,$color);    
        imagestring($img,1,571,$h18-10,$hour[18],$color);    
        imagestring($img,1,571,195,18,$bc);    

        //19点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,601,$h19,615,189,$color);    
        imagestring($img,1,601,$h19-10,$hour[19],$color);    
        imagestring($img,1,604,195,19,$bc);    

        //20点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,631,$h20,645,189,$color);    
        imagestring($img,1,631,$h20-10,$hour[20],$color);    
        imagestring($img,1,634,195,20,$bc);    

        //21点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,661,$h21,675,189,$color);    
        imagestring($img,1,661,$h21-10,$hour[21],$color);    
        imagestring($img,1,664,195,21,$bc);    

        //22点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,691,$h22,705,189,$color);    
        imagestring($img,1,691,$h22-10,$hour[22],$color);    
        imagestring($img,1,694,195,22,$bc);    

        //23点    
        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));    
        imagefilledrectangle($img,721,$h23,735,189,$color);    
        imagestring($img,1,721,$h23-10,$hour[23],$color);    
        imagestring($img,1,724,195,23,$bc);    

        //加个边框 加了之后不好看    
        //imagerectangle($img, 0, 0, 754, 209, $bc);    

        imagepng($img);    
        imagedestroy($img);            
}    
$str = isset($_GET['str'])?$_GET['str']:"";    
if($str){    
        h24($str);    
}    
?>

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

PHP는 주로 절차 적 프로그래밍이지만 객체 지향 프로그래밍 (OOP)도 지원합니다. Python은 OOP, 기능 및 절차 프로그래밍을 포함한 다양한 패러다임을 지원합니다. PHP는 웹 개발에 적합하며 Python은 데이터 분석 및 기계 학습과 같은 다양한 응용 프로그램에 적합합니다.

PHP와 Python : 그들의 역사에 깊은 다이빙PHP와 Python : 그들의 역사에 깊은 다이빙Apr 18, 2025 am 12:25 AM

PHP는 1994 년에 시작되었으며 Rasmuslerdorf에 의해 개발되었습니다. 원래 웹 사이트 방문자를 추적하는 데 사용되었으며 점차 서버 측 스크립팅 언어로 진화했으며 웹 개발에 널리 사용되었습니다. Python은 1980 년대 후반 Guidovan Rossum에 의해 개발되었으며 1991 년에 처음 출시되었습니다. 코드 가독성과 단순성을 강조하며 과학 컴퓨팅, 데이터 분석 및 기타 분야에 적합합니다.

PHP와 Python 중에서 선택 : 가이드PHP와 Python 중에서 선택 : 가이드Apr 18, 2025 am 12:24 AM

PHP는 웹 개발 및 빠른 프로토 타이핑에 적합하며 Python은 데이터 과학 및 기계 학습에 적합합니다. 1.PHP는 간단한 구문과 함께 동적 웹 개발에 사용되며 빠른 개발에 적합합니다. 2. Python은 간결한 구문을 가지고 있으며 여러 분야에 적합하며 강력한 라이브러리 생태계가 있습니다.

PHP 및 프레임 워크 : 언어 현대화PHP 및 프레임 워크 : 언어 현대화Apr 18, 2025 am 12:14 AM

PHP는 현대화 프로세스에서 많은 웹 사이트 및 응용 프로그램을 지원하고 프레임 워크를 통해 개발 요구에 적응하기 때문에 여전히 중요합니다. 1.PHP7은 성능을 향상시키고 새로운 기능을 소개합니다. 2. Laravel, Symfony 및 Codeigniter와 같은 현대 프레임 워크는 개발을 단순화하고 코드 품질을 향상시킵니다. 3. 성능 최적화 및 모범 사례는 응용 프로그램 효율성을 더욱 향상시킵니다.

PHP의 영향 : 웹 개발 및 그 이상PHP의 영향 : 웹 개발 및 그 이상Apr 18, 2025 am 12:10 AM

phphassignificallyimpactedwebdevelopmentandextendsbeyondit

스칼라 유형, 반환 유형, 노조 유형 및 무효 유형을 포함한 PHP 유형의 힌트 작업은 어떻게 작동합니까?스칼라 유형, 반환 유형, 노조 유형 및 무효 유형을 포함한 PHP 유형의 힌트 작업은 어떻게 작동합니까?Apr 17, 2025 am 12:25 AM

PHP 유형은 코드 품질과 가독성을 향상시키기위한 프롬프트입니다. 1) 스칼라 유형 팁 : PHP7.0이므로 int, float 등과 같은 기능 매개 변수에 기본 데이터 유형을 지정할 수 있습니다. 2) 반환 유형 프롬프트 : 기능 반환 값 유형의 일관성을 확인하십시오. 3) Union 유형 프롬프트 : PHP8.0이므로 기능 매개 변수 또는 반환 값에 여러 유형을 지정할 수 있습니다. 4) Nullable 유형 프롬프트 : NULL 값을 포함하고 널 값을 반환 할 수있는 기능을 포함 할 수 있습니다.

PHP는 객체 클로닝 (클론 키워드) 및 __clone 마법 방법을 어떻게 처리합니까?PHP는 객체 클로닝 (클론 키워드) 및 __clone 마법 방법을 어떻게 처리합니까?Apr 17, 2025 am 12:24 AM

PHP에서는 클론 키워드를 사용하여 객체 사본을 만들고 \ _ \ _ Clone Magic 메소드를 통해 클로닝 동작을 사용자 정의하십시오. 1. 복제 키워드를 사용하여 얕은 사본을 만들어 객체의 속성을 복제하지만 객체의 속성은 아닙니다. 2. \ _ \ _ 클론 방법은 얕은 복사 문제를 피하기 위해 중첩 된 물체를 깊이 복사 할 수 있습니다. 3. 복제의 순환 참조 및 성능 문제를 피하고 클로닝 작업을 최적화하여 효율성을 향상시키기 위해주의를 기울이십시오.

PHP vs. Python : 사용 사례 및 응용 프로그램PHP vs. Python : 사용 사례 및 응용 프로그램Apr 17, 2025 am 12:23 AM

PHP는 웹 개발 및 컨텐츠 관리 시스템에 적합하며 Python은 데이터 과학, 기계 학습 및 자동화 스크립트에 적합합니다. 1.PHP는 빠르고 확장 가능한 웹 사이트 및 응용 프로그램을 구축하는 데 잘 작동하며 WordPress와 같은 CMS에서 일반적으로 사용됩니다. 2. Python은 Numpy 및 Tensorflow와 같은 풍부한 라이브러리를 통해 데이터 과학 및 기계 학습 분야에서 뛰어난 공연을했습니다.

See all articles

핫 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를 무료로 생성하십시오.

뜨거운 도구

SublimeText3 Linux 새 버전

SublimeText3 Linux 새 버전

SublimeText3 Linux 최신 버전

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

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

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

PhpStorm 맥 버전

PhpStorm 맥 버전

최신(2018.2.1) 전문 PHP 통합 개발 도구

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 통합 개발 환경