PHP头条
热点:

phplot生成图片类用法详解


   本文实例讲述了phplot生成图片类用法。分享给大家供大家参考。具体分析如下:

  phplot是一个利用php的图象函数编写的一个自动生成类,首先申明一下,我对他也只是了解. 在原来的有些版本好象还需要多方面的配置和支持,不过现在都用的是php5系列了,大家只要了解一些常用到的函数,就比如我们学习一种软件一样,只需要懂得怎样使用他就可以了,如果感兴趣的朋友可以深入的学习学习,不过对于我们大多数的朋友来说,只要会使用他就可以了,毕竟也不是常用,只是需要用php作图的时候才用到他。所以我们只需要知道他怎么用就可以了,那么就必须知道他的函数的作用,好比我们学习discuz一样,要懂得怎么用他就可以了!

  他的常用函数分为几个类:配置函数,显示函数,颜色函数.

  1.配置函数:配置phplot使用什么样的类型,以及以什么样的方式显示图象。

  a.SetDataType($which_dt):设定使用的数据类型,在这个里面可以使用多种类型。

  (1)text-date:数据沿着x柱,等间距排行。每个数组元素代表x轴上的某一位置的点,他同时也是数组,第一个元素代表x坐标,后面的所有元素都代表y坐标。

  (2) data-data:与上面的类型相似,不同的是数值数组的第二个元素代表x坐标,后面的代表y坐标,而第一个元素仅仅是一个标签。

  (3)data-data-error:与data-data类似,不同的是他的数值数组后面还有两个元素代表error_plus和error_minus,如

  (data_labl,x_position,y_position,error_plus,error_minus).

  b.SetDataValues($which_dv):把一个数组$which_dv赋给类的一个变量$this->data_values.这个函数要开始作图之前调用。

  c.SetPlotType($which_pt):设定图表的类型,可以是bars,lines,linepoints,area,points,pie等。

  d.SetErrorBarLineWidth($wd):设定错误栏的宽度。

  e.SetFileFormat($which_file_format):设定输出的图象文件的格式,可以是GIF,PNG,JPEG等。还有要看你的GD库是否支持。

  f.SetUseTTF($which_ttf):设定是否使用TTF,如果编译php支持TTF,就使用SetUseTTF("1");否则设置为0.

  2.显示函数:显示图象设定输出图表所使用的线条的类型,宽度等参量,还可以设定坐标轴刻度的间距,图表的大小等。

  a.SetErrorBarShape($which_ebs):设定精度线的类型,可以是line或者是tee,如果是tee,则T型线的半度设定为SetErrorBarSize.

  b.SetErrprBarSize($which_ebs):设置精度线的宽度。

  c.SetHorizTickIncreament($which_ti):设定x轴的显示刻度的间距。

  d.SetHorizTicks($whick_nt):设定x轴显示刻度的个数。(不能和SetHorizTickIncreament)

  e.SetNumVertTicks($which_nt):设定x轴显示刻度的个数。(不能和SetVertTickIncreament)

  f.SetPlotArearpixels($x1,$y1,$x2,$y2):设定图表大小。

  g.SetPointShape($which_pt):设置定点的形状:rect,circle,diamond,triangle,dot,line,halfline.

  h.SetPointSize($whick_ps教程):设定点的宽度。

  i.SetPrecisionX($whick_prec):设定x轴的精度。$whick_prec代表小数点后面数字的个数。

  j.SetPrecisiony($whick_prec)设定y轴的精度。$whick_prec代表小数点后面数字的个数。

  k.SetSjading($whick_s):设定阴影的宽度。

  l.SetTickLength($which_tl):设定坐标轴上的标记线的长度,单位为pixel.

  m.SetTile($title):设定图表的标题。

  n.SetVertTickIncreament($whick_ti):和SetHorizTicks($whick_nt)这两个函数用于设定坐标轴上标记线的垂直和水平间隔。

  o.SetXDataLabelMaxlength($which_xdlm):设定x轴上的标签的最大长度。

  p.SetXGridLabelType($which_xtf):设定x轴的标签类型,可以是time,title,data,none或者default.

  (1).time:由函数strftime()设定。

  (2).title:文本类型。

  (3).data:用函数number_format()格式化数字。

  (4).none:没有任何标签。

  (5).default:按照输入的形式输出.

  3.颜色函数:颜色函数用于设定图表中的各元素的显示颜色,包括图象背景颜色,删格线的颜色,标题颜色等!

  a.SetBackgroundColor($which_color):设定整个图象的背景颜色。

  b.SetGridColor($which_color):设定删格线的颜色。

  c.SetLegend($which_legend):参数是一个文本数组,他的内容显示在一个图列框中。

  d.SetLegendPixels($which_x,$which_y,$which_type):设定图列框左下角点的坐标,最后一个参数以后可用。

  e.SetLightGridColor($which_color):删割线线有两种颜色,这个函数设定其中的一种。

  f.SetLineWidth($which_lt):设定图表中使用的线宽,他也影响精度线的宽度。

  g.SetLineStyles($which_sls):设定线条的类型,可以是实线或者虚线。

  h.SetPlotBgColor($which_color):设定使用SetPlotAreaPixels()函数设定的区域的颜色。

  i.SetTextColor($which_color):设定文本的颜色,默认是黑色。

  j.SetTickColor($which_color):设定坐标轴上刻线的颜色。

  k.SetTitleColor($which_color):设定标题颜色。

  看个实例,生成上面图形的代码如下:

  代码如下:# PHPlot Demo

  # 2008-01-09 ljb

  # For more information see http://sourceforge.net/projects/phplot/

  # Load the PHPlot class library:

  require_once 'phplot.php';

  # Define the data array: Label, the 3 data sets.

  # Year, Features, Bugs, Happy Users:

  $data = array(

  array('2001', 60, 35, 20),

  array('2002', 65, 30, 30),

  array('2003', 70, 25, 40),

  array('2004', 72, 20, 60),

  array('2005', 75, 15, 70),

  array('2006', 77, 10, 80),

  array('2007', 80, 5, 90),

  );

  # Create a PHPlot object which will make a 600x400 pixel image:

  $p = new PHPlot(600, 400);

  # Use TrueType fonts:

  $p->SetDefaultTTFont('./arial.ttf');

  # Set the main plot title:

  $p->SetTitle('PHPlot Customer Satisfaction (estimated)');

  # Select the data array representation and store the data:

  $p->SetDataType('text-data');

  $p->SetDataValues($data);

  # Select the plot type - bar chart:

  $p->SetPlotType('bars');

  # Define the data range. PHPlot can do this automatically, but not as well.

  $p->SetPlotAreaWorld(0, 0, 7, 100);

  # Select an overall image background color and another color under the plot:

  $p->SetBackgroundColor('#ffffcc');

  $p->SetDrawPlotAreaBackground(True);

  $p->SetPlotBgColor('#ffffff');

  # Draw lines on all 4 sides of the plot:

  $p->SetPlotBorderType('full');

  # Set a 3 line legend, and position it in the upper left corner:

  $p->SetLegend(array('Features', 'Bugs', 'Happy Users'));

  $p->SetLegendWorld(0.1, 95);

  # Turn data labels on, and all ticks and tick labels off:

  $p->SetXDataLabelPos('plotdown');

  $p->SetXTickPos('none');

  $p->SetXTickLabelPos('none');

  $p->SetYTickPos('none');

  $p->SetYTickLabelPos('none');

  # Generate and output the graph now:

  $p->DrawGraph();

www.phpzy.comtrue/php/24578.htmlTechArticlephplot生成图片类用法详解 本文实例讲述了phplot生成图片类用法。分享给大家供大家参考。具体分析如下: phplot是一个利用php的图象函数编写的一个自动生成类,首先申明一下,我对他...

相关文章

    暂无相关文章

PHP之友评论

今天推荐