Php plotting, please modify the saint.

Source: Internet
Author: User
Php drawing. please modify it .. & Lt ;? $ Kuan30; color bar width $ jiange20; color bar interval $ zuo20; left blank $ you20; right blank $ shang20; left blank $ xia10; left blank $ zuidashujuzhi1; initialize the if & nbsp; ($ _ GET [a]) & nbsp; die (error & nb php drawing, please modify it ..
 $ Kuan = 30; // color bar width
$ Jiange = 20; // interval between color bars
$ Zuo = 20; // left blank
$ You = 20; // leave it blank on the right
$ Shang = 20; // leave it empty
$ Xia = 10; // leave it blank
$ Zuidashujuzhi = 1; // initialize the maximum data value of the vertical axis.
If ($ _ GET ["a"] = "") die ("error id: 0 ");
$ Shuju = split (",", $ _ GET ["a"]);
// Obtain the maximum value.
For ($ I = 0; $ I If (! Is_numeric ($ shuju [$ I]) die ("error id: 1 ");
If ($ shuju [$ I]> $ zuidashujuzhi) $ zuidashujuzhi = $ shuju [$ I];
}
// Calculate the image width
$ Img_kuan = $ zuo + $ you + $ jiange + count ($ shuju) * ($ kuan + $ jiange );
// Image height
$ Img_gao = 170;
// An Array storing the color column height
$ Zhugaodu = array ();
$ Image = imagecreate ($ img_kuan, $ img_gao );
$ White = imagecolorallocate ($ image, 0xEE, 0xEE, 0xEE );
// Color bar color
$ Shuju_yanse = array (
Imagecolorallocate ($ image, 0x97, 0xbd, 0x00 ),
Imagecolorallocate ($ image, 0x00, 0x99, 0x00 ),
Imagecolorallocate ($ image, 0xcc, 0x33, 0x00 ),
Imagecolorallocate ($ image, 0xff, 0xcc, 0x00 ),
Imagecolorallocate ($ image, 0x33, 0x66, 0xcc ),
Imagecolorallocate ($ image, 0x33, 0xcc, 0x33 ),
Imagecolorallocate ($ image, 0xff, 0x99, 0x33 ),
Imagecolorallocate ($ image, 0xcc, 0xcc, 0x99 ),
Imagecolorallocate ($ image, 0x99, 0xcc, 0x66 ),
Imagecolorallocate ($ image, 0x66, 0xff, 0x99)
);



// Coordinate axis color
$ Zuobiao_yanse = imagecolorallocate ($ image, 0x00, 0x00, 0x00 );
// Horizontal axis
Imageline ($ image, $ zuo, $ img_gao-$ xia, $ img_kuan-$ you/2, $ img_gao-$ xia, $ zuobiao_yanse );
// Vertical axis
Imageline ($ image, $ zuo, $ shang/2, $ zuo, $ img_gao-$ xia, $ zuobiao_yanse );



// The scale of the vertical axis. a total of four vertices are marked on the vertical axis. Therefore, calculate them here.
Imageline ($ image, $ zuo, $ shang, $ zuo + 6, $ shang, $ zuobiao_yanse );
Imagestring ($ image, 3, $ zuo/4, $ shang, round ($ zuidashujuzhi), $ zuobiao_yanse );
Imageline ($ image, $ zuo, $ shang + ($ img_gao-$ shang-$ xia) * 1/4, $ zuo + 6, round ($ shang + ($ img_gao-$ shang-$ xia) * 1/4), $ zuobiao_yanse );
Imagestring ($ image, 3, $ zuo/4, $ shang + ($ img_gao-$ shang-$ xia) * 1/4, round ($ zuidashujuzhi * 3/4), $ zuobiao_yanse );
Imageline ($ image, $ zuo, $ shang + ($ img_gao-$ shang-$ xia) * 2/4, $ zuo + 6, $ shang + ($ img_gao-$ shang-$ xia) * 2/4, $ zuobiao_yanse );
Imagestring ($ image, 3, $ zuo/4, $ shang + ($ img_gao-$ shang-$ xia) * 2/4, round ($ zuidashujuzhi * 2/4), $ zuobiao_yanse );
Imageline ($ image, $ zuo, $ shang + ($ img_gao-$ shang-$ xia) * 3/4, $ zuo + 6, $ shang + ($ img_gao-$ shang-$ xia) * 3/4, $ zuobiao_yanse );
Imagestring ($ image, 3, $ zuo/4, $ shang + ($ img_gao-$ shang-$ xia) * 3/4, round ($ zuidashujuzhi * 1/4), $ zuobiao_yanse );



// Obtain the height of each column
For ($ I = 0; $ I Array_push ($ zhugaodu, round ($ img_gao-$ shang-$ xia) * $ shuju [$ I]/$ zuidashujuzhi ));
}
// Draw a data column
$ Shuju_yanse_int = 0;
For ($ I = 0; $ I Imagefilledrectangle ($ image, $ zuo + $ jiange + $ I * ($ kuan + $ jiange), $ shang + ($ img_gao-$ shang-$ xia) -$ zhugaodu [$ I], $ zuo + $ jiange + $ I * ($ kuan + $ jiange) + $ kuan, ($ img_gao-$ xia)-1, $ shuju_yanse [$ shuju_yanse_int]);
// Because only 10 colors are defined, a loop is made here.
If ($ shuju_yanse_int = 9 ){
$ Shuju_yanse_int = 0;
} Else {
$ Shuju_yanse_int ++;
}
}
// Mark the data value above the data column
For ($ I = 0; $ I Imagestring ($ image, 1, $ zuo + $ jiange + $ I * ($ kuan + $ jiange) + 2, $ shang + ($ img_gao-$ shang-$ xia) -$ zhugaodu [$ I]-10, $ shuju [$ I], $ zuobiao_yanse );
}
Header ('content-type: image/png ');
Imagepng ($ image );
Imagedestroy ($ image );
?>


This can generate

Img. php? A = 5.4, 2, 30.2, 7.7, 6, 3.8, 4
Use the following parameter to obtain the image above ..
Now I want to get the column name, for example, 5.4. I divide it into three more attributes and display the name of each column. how can I improve the code.


And there is no limit on the number of types below, such as steel pipes, aluminum tubes, copper tubes, gold tubes ,..... There are several.
But there are only three attributes .... Each is an integer...

Please help me modify the code or give me a simple code .. Thanks.

Share:


------ Solution --------------------
Take a look at the API and look for their example. copy it and modify the parameters.
The JS chart library is very convenient to use. There should be a case that fits your needs: Highcharts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.