使用jpgraph画图
2011-05-16 20:56
120 查看
最近完成了一个项目,正好其中有很多地方需要用到php画图的功能,然后对生成的图片,通过jpgraph将生产的html,
使用HTML2PDF类将html转化为pdf,然后通过pdf2swf让生产的pdf转化为swf文件,
同时其中有些地方用到了popen函数,用来打开一个打开进程文件指针,比如:
$handle = popen("nohup php " . PROJECT_PATH. "/cron/Index.php Report);
pclose($handle);
这样可以使用nohup让程序永远后台运行。
其中有些地方同时使用了jpgraph和GD库绘图,这样有利于结合原生的GD功能,例如:
这样就可以结合jpgraph了。不过一般情况下不会使用到该类,因为如果有更酷的需要,会使用到js的绘图类库,比如:
FusionChart,和AmChart,这样可以更好的使用flash,更炫!
使用HTML2PDF类将html转化为pdf,然后通过pdf2swf让生产的pdf转化为swf文件,
同时其中有些地方用到了popen函数,用来打开一个打开进程文件指针,比如:
$handle = popen("nohup php " . PROJECT_PATH. "/cron/Index.php Report);
pclose($handle);
这样可以使用nohup让程序永远后台运行。
其中有些地方同时使用了jpgraph和GD库绘图,这样有利于结合原生的GD功能,例如:
ini_set("display_errors", "On"); //图片原始大小 $baseWidth = 400; $baseHeight = 400; $extensionHeight = 50; //作图位置 $left = 30; $right = 380; $top = 32; $bottom = 392; $height = 362; $length = 10; $lineLength = 5; $srcFile = Ggzg_Config::get("base.url")."/ggdx/gsggdxHalf/?code=" . $stockCode; $picData = GetImageSize($srcFile); switch ($picData[2]) { case 1: //图片类型,1是GIF图 $img = ImageCreateFromGIF($srcFile); break; case 2: //图片类型,2是JPG图 $img = imagecreatefromjpeg($srcFile); break; case 3: //图片类型,3是PNG图 $img = ImageCreateFromPNG($srcFile); break; } //中间变量图片 $tempImg = imagecreate($baseWidth, $baseHeight + $extensionHeight); $bg = imagecolorallocate($tempImg, 255, 255, 255); $im = imagecreatetruecolor($baseWidth, ($baseHeight + $extensionHeight)); //复制图片 imagecopyresized($tempImg, $img, 0, 0, 0, 0, $baseWidth, $baseHeight, $baseWidth, $baseHeight); imagecopyresized($im, $tempImg, 0, 0, 0, 0, $baseWidth, $baseHeight + $extensionHeight, $baseWidth, $baseHeight + $extensionHeight); //确定作图位置 $color = imagecolorallocate($tempImg, 200, 200, 200); //测试位置坐标 // imagettftext($im, 10, 0,54, 360, // $color, TTF_DIR . "simsun.ttc", "正法"); /** * 确定坐标位置 */ $count = count($date); // print_r($date);exit; //存放小图标横坐标以及类型的数组 $icon = array(); $interval = ($right - $left) / $count; // echo $interval;exit; for ($i = 0; $i < $count; $i ++) { for ($j = 0; $j < count($arrow); $j ++) { if ($date[$i] == $arrow[$j][0]) { $icon[] = array( 'index' => round($i * $interval), 'type' => $arrow[$j][1] ); } } } $white = imagecolorallocate($im, 255, 255, 255); //作图开始 for ($i = 0; $i < count($icon); $i ++) { $x = $icon[$i]['index']+$left; $p = array( $x, $height, ($x + $length), $height, ($x + $length), ($height + $length), $x, ($height + $length) ); switch ($icon[$i]['type']) { case 1: $color = imagecolorallocate($im, 253, 15, 16); imagefilledpolygon($im, $p, 4, $color); imageline($im, ($x + 1), ($height + 7), ($x + $lineLength), ($height + 3), $white); imageline($im, ($x + $lineLength), ($height + 3), ($x + 9), ($height + 7), $white); break; case 2: $color = imagecolorallocate($im, 22, 187, 0); imagefilledpolygon($im, $p, 4, $color); imageline($im, ($x + 1), ($height + 3), ($x + $lineLength), ($height + 7), $white); imageline($im, ($x + $lineLength), ($height + 7), ($x + 9), ($height + 3), $white); break; case 3: $color = imagecolorallocate($im, 255, 192, 0); imagefilledpolygon($im, $p, 4, $color); imageline($im, ($x + 1), ($height + 5), ($x + 9), ($height + 5), $white); break; } } $legendLeft = 40; $legendRight = 370; $legendTop = 410; $legendBottom = 440; //图例区域 $legendArr = array( $legendLeft, $legendTop, $legendRight, $legendTop, $legendRight, $legendBottom, $legendLeft, $legendBottom ); $bg = imagecolorallocate($im, 231, 247, 255); imagefilledpolygon($im, $legendArr, 4, $bg); $white = imagecolorallocate($im, 255, 255, 255); $black = imagecolorallocate($im, 0, 0, 0); $sep = 110; $yBegin = 10 + $legendTop; for ($i = 0; $i < 3; $i ++) { $xBegin = $legendLeft + 20 + $i * 110; $p = array( $xBegin, $yBegin, ($xBegin + $length), $yBegin, ($xBegin + $length), ($yBegin + $length), $xBegin, ($yBegin + $length) ); switch ($i) { case 0: $color = imagecolorallocate($im, 253, 15, 16); imagefilledpolygon($im, $p, 4, $color); imageline($im, ($xBegin + 1), ($yBegin + 7), ($xBegin + $lineLength), ($yBegin + 3), $white); imageline($im, ($xBegin + $lineLength), ($yBegin + 3), ($xBegin + 9), ($yBegin + 7), $white); //文字 imagettftext($im, 10, 0, ($xBegin + 12), ($yBegin + 10), $black, TTF_DIR . "simsun.ttc", "仅买入,不卖出"); break; case 1: $color = imagecolorallocate($im, 22, 187, 0); imagefilledpolygon($im, $p, 4, $color); imageline($im, ($xBegin + 1), ($yBegin + 3), ($xBegin + $lineLength), ($yBegin + 7), $white); imageline($im, ($xBegin + $lineLength), ($yBegin + 7), ($xBegin + 9), ($yBegin + 3), $white); imagettftext($im, 10, 0, ($xBegin + 12), ($yBegin + 10), $black, TTF_DIR . "simsun.ttc", "仅卖出,无买入"); break; case 2: $color = imagecolorallocate($im, 255, 192, 0); imagefilledpolygon($im, $p, 4, $color); imageline($im, ($xBegin + 1), ($yBegin + 5), ($xBegin + 9), ($yBegin + 5), $white); imagettftext($im, 10, 0, ($xBegin + 12), ($yBegin + 10), $black, TTF_DIR . "simsun.ttc", "有买有卖"); break; } } header("content-type:image/gif"); ImageJpeg($im); imagedestroy($im); }
这样就可以结合jpgraph了。不过一般情况下不会使用到该类,因为如果有更酷的需要,会使用到js的绘图类库,比如:
FusionChart,和AmChart,这样可以更好的使用flash,更炫!
相关文章推荐
- PHP使用jpgraph画图,以柱状图为例
- PHP 画图——使用jpgraph画图
- 使用Graphics中的drawRect画图遇到的问题
- WPF InkCanvas 画图 基础使用教程
- iOS画图-UIBezierPath和CAShapeLayer的简单使用
- Mac使用 matplotlib 画图 => RuntimeError: Python is not installed as a framework
- Android画图Path的使用
- Python 3下使用Matplotlib工具画图,中文显示乱码的问题解决(修改配置文件)
- 画图工具PaintCode的使用
- 使用python画图(3)
- 使用JS画图之点、线、面
- Windows7电脑基础使用画图程序画一个小鸭
- 使用JpGraph生成三维饼图
- nf使用 Python 的 turtle 模块画图
- 使用jpgraph
- php中使用jpGraph一点总结
- php使用Jpgraph绘制饼状图的方法
- 【转】使用Sublime + PlantUML高效地画图
- php使用Jpgraph绘制复杂X-Y坐标图的方法
- Python 使用matplotlib画图添加标注、及移动坐标轴位置