PHP drawing, please change sage.

Source: Internet
Author: User
PHP drawing, please modify the expert.
 $kuan =30;//Color Column width
$jiange =20;//spacing between columns
Left blank $zuo =20;//
$you =20;//Right Blank
Leave blank on $shang =20;//
Leave blank $xia =10;//
$zuidashujuzhi =1;//Initialize the vertical axis maximum data value
if ($_get["a"]== "") Die ("Error id:0");
$shuju =split (",", $_get["a"]);
Get maximum Value
for ($i =0; $i <>
if (!is_numeric ($shuju [$i])) die ("Error id:1");
if ($shuju [$i]> $zuidashujuzhi) $zuidashujuzhi = $shuju [$i];
}
Calculate Image width
$img _kuan= $zuo + $you + $jiange +count ($shuju) * ($kuan + $jiange);
High image
$img _gao=170;
Array that stores the height of the color column
$zhugaodu = Array ();
$image = Imagecreate ($img _kuan, $img _gao);
$white = Imagecolorallocate ($image, 0xEE, 0xEE, 0xEE);
Color of color column
$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)
);



Axis Color
$zuobiao _yanse = imagecolorallocate ($image, 0x00, 0x00, 0x00);
Horizontal
Imageline ($image, $zuo, $img _gao-$xia, $img _kuan-$you/2, $img _gao-$xia, $zuobiao _yanse);
longitudinal axis
Imageline ($image, $zuo, $shang/2, $zuo, $img _gao-$xia, $zuobiao _yanse);



Vertical axis scale, a total of 4 points on the vertical axis, so here can be calculated separately
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);



Get the height of each bar
for ($i =0; $i <>
Array_push ($zhugaodu, round ($img _gao-$shang-$xia) * $shuju [$i]/$zuidashujuzhi)];
}
Draw 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, so here's a loop
if ($shuju _yanse_int==9) {
$shuju _yanse_int=0;
}else{
$shuju _yanse_int++;
}
}
Labeling data values above data bars
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 way you can generate

img.php?a=5.4,2,30.2,4,0,6,7.7,3.8,2,3,4
Use the following parameter to get the picture above:
I now want to get to such as 5.4 inside, I divided into three properties, and display the name of each column, how to improve the code.


And the following types are not limited, such as steel pipe, aluminum tube, copper tube, gold tube, ... There are a number of.
But there are only three properties .... Each is an integer ...

Ask an expert to help modify the code, or give me a simple code. Thank you so much.

Share to:


------Solution--------------------
Look at the API, look for their example, copy it to modify the next parameter.
JS Chart Library With this is very convenient, should have to match your case: 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.