温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

phplot中如何使用图片生成类

发布时间:2021-07-12 10:10:11 来源:亿速云 阅读:123 作者:Leah 栏目:开发技术

今天就跟大家聊聊有关phplot中如何使用图片生成类,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

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();

看完上述内容,你们对phplot中如何使用图片生成类有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI