php怎么创建两条折线图,php创建折线图

改了一下颜色,很酷吧:

0818b9ca8b590ca3270a3433284dd417.png

10.通过这个例子,可以知道,imagefill虽然可以给图像画布填充颜色,但如果不出现这一操作,画布就会被填充imagecolorallocate第一次出现时设置的颜色;从网上搜索得知imagepng等函数可以指定图片的名称,但实验过后没有成功。

11.把上面的所有内容总结成一个函数:

header("Content-type:text/html;charset='utf-8'");

function createImage($width,$height,$arrayData){

//定义坐标轴起始点坐标值;

//X-起点

$x1 = 40;

$x2 = 360;

//X-终点

$x3 = 520;

$x4 = 360;

//Y-起点;

$y1 = 40;

$y2 = 20;

//Y-终点

$y3 = 40;

$y4 = 360;

//定义字号;

$font = 10;

$panel = imagecreate($width, $height);

$red = imagecolorallocate($panel, 255, 0, 0);

$green = imagecolorallocate($panel, 0, 222, 20);

$white = imagecolorallocate($panel, 255, 255, 255);

$black = imagecolorallocate($panel, 0, 0, 0);

imagefill($panel, 0, 0, $black);  //填充背景;

imageline($panel, $x1, $x2, $x3, $x4, $green);   //X轴

imageline($panel, $y1, $y2, $y3, $y4, $green);   //Y轴

imagestring($panel, $font, 20, 15, 'X', $green);   //X字符

imagestring($panel, $font, 526, 370, 'Y', $green);   //Y字符

//与X轴平行的轴线;

$step_x = 330; //定义第一条网线起始点纵坐标;

for ($i=0; $i<10; $i++){

imageline($panel, 40, $step_x, 510, $step_x, $green);

$step_x -= 30;

}

//与Y轴平行的轴线;

$step_y = 70; //定义第一条网线起始点横坐标;

for ($i=0; $i<12; $i++){

imageline($panel, $step_y, 35, $step_y, 360, $green);

$step_y += 40;

}

//定义X轴参数;

$y_point = array_values(range(1,12));

//输出X轴参数;

$x_str = 67;  //定义初始横坐标值;

$font = 2;

for($j = 0; $j<12; $j++){

imagestring($panel, $font, $x_str, 370, $y_point[$j], $red);

$x_str += 40;

}

//定义Y轴参数;

$x_point = array(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1);

$y_str = 355;

$font = 2;

for($j = 0; $j<11; $j++){

$xp = $x_point[$j]*100;

imagestring($panel, $font, 15, $y_str, $xp.'%', $red);

$y_str -= 30;

}

//本函数关键:画折线!

$line_x = 70;  //这是一月份点的横坐标;

$data= array(0.3,0.5,0.6555,0.7,0.85,0.65,0.33,0.90,0.22,0.77,0.56,0.16);

for($r = 1; $r<12; $r++){

$line_y = 360 - $data[$r-1] * 300;

$line_y2 = 360 - $data[$r] * 300;

imageline($panel, $line_x, $line_y, $line_x + 40, $line_y2, $red);

$line_x += 40;

}

imagepng($panel);

imagedestroy($panel);

}

createImage(550, 400, $arrayData);

0818b9ca8b590ca3270a3433284dd417.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值