<?php
//定数ファイルを読み込み
require_once("../../../app/webapp/const/const.php");
//DB
require_once(PATH."/db/MysqlPdo.php");
//共通関数
require_once(WEBAPP_FUNCTION_PATH."/common.php");
header("Content-Type:image/png");
$width = 240; //定义画布宽度
$height= 190; //定义画布高度
$unit = 40; //定义刻度间隔
$right = 20; //定义坐标系距画布右侧距离
$left = 30; //定义坐标系距画布左侧距离
$top = 20; //定义坐标系距画布上侧距离
$buttom= 30; //定义坐标系距画布下侧距离
$x = array(); //定义x坐标空数组
$y = array(); //定义y坐标空数组
$max=0;
$string_CO = 'CO';
$string_2 = '2';
$name = array( '0','6','12','18','24' ); //定义横坐标的坐标标签
$image = imagecreatetruecolor($width, $height);
//控制透明
imagesavealpha($image, true);
//透明色 127全透
$whiteTransparent = imagecolorallocatealpha($image, 255, 255, 255,127); //定义真彩画布及颜色值//
//定义颜色
$white = imagecolorallocate($image, 255, 255, 255);
imagefill( $image, 0, 0, $whiteTransparent ); //用透明色填充画布
//从数据库得到数据
$datas = getDrawLineDates();
if(!empty($datas)){
//对数据进行处理;
$datas = datas_convert($datas);
$data_co = $datas['co'];
// $data_co = array ( '0', '0', '0','0', '0', '0', '0', '0', '0','0', '0', '0', '10','0','0', '0');
// print_r($data_co);exit;
for ( $i = 0; $i < count($data_co); $i++ ){ //获取$data中最大值
if( $data_co[$i] > $max ){
$max = $data_co[$i];
}
}
//计算$data数组中每个元素的坐标
for ($i = 0;$i < count($data_co) ; $i++){
$x[$i] = $left + round( $i*160/144 );
$y[$i] = $top + round( $height - $top - $buttom )*( 1 - $data_co[$i]/$max );
}
//绘制数据折线图
for ( $i=0; $i<count($data_co); $i++ ){
if ( $i+1!=count($data_co) ){
imageline($image, $x[$i], $y[$i], $x[$i+1], $y[$i+1], $white);
}
}
}
//画出横坐标
for ( $i = 0;$i<5;$i++ ){
imageline($image, $left + $i*$unit, $height - $buttom, $left + $i*$unit, $height - $buttom - 4, $white);
imagestring($image, 1, $left+$i*$unit, $height-$buttom+1, $name[$i], $white);
}
//画出纵坐标
for( $i = 0; $i<5; $i++ ){
imageline($image, $left, round($top + ($height-$top-$buttom)*$i / 5), $left+5, round($top+($height-$top-$buttom)*$i/5), $white);
imagestring($image, 1, $left/4, $top+($height-$top-$buttom)*$i/5, round($max*(5-$i)/5), $white);
}
//画横坐标
imageline( $image, $left, $height-$buttom, $width-$right, $height-$buttom, $white );
//画纵坐标
imageline( $image, $left, $buttom, $left, $height-$buttom, $white );
//画箭头
imageline( $image, $width-$right, $height-$buttom, ($width-$right)-8,$height-$buttom-3, $white );
imageline( $image, $width-$right, $height-$buttom, ($width-$right)-8,$height-$buttom+3, $white );
imageline( $image, $left, $top/4+16, $left+3, $top/4+24, $white );
imageline( $image, $left, $top/4+16, $left-3, $top/4+24, $white );
//绘制图像说明
imageline($image, $left, 180, $left+10,180, $white);
imagestring($image, 2, $left+20, 175, $string_CO, $white);
imagechar($image, 1, $left+35, 179, $string_2, $white);
//ob_clean();
//输出图形
imagepng($image);
//销毁图形资源
imagedestroy($image);
为什么在数据库中新添加一条数据之后,网页动态刷新,更新画图图片,图片就不出了了
求大神指点!!