Phplot generate picture Class usage detailed

Source: Internet
Author: User

This example describes the use of Phplot to generate picture classes. Share to everyone for your reference. The specific analysis is as follows:

Phplot is an automatic generation class written using PHP's image function, first of all stating that I only know him. In some of the original versions it seems that there is a need for multiple configurations and support, but now all use is PHP5 series, everybody just understand some commonly used function, just like we learn a kind of software, just want to know how to use him to be able, if interested friend can deep study study, But for most of our friends, as long as the use of him can be, after all, is not commonly used, just need to use PHP to draw when the use of him. So we just need to know how he can use, then must know his function, like we learn discuz like, to know how to use him on it!

His common functions are divided into several classes: Configuration functions, display functions, color functions.

1. Configuration function: Configure what type of Phplot to use, and how to display the image in what way.

A.setdatatype ($which _dt): Set the type of data used, in which you can use multiple types.

(1) Text-date: The data is ranked along the X-pillar, equal spacing. Each array element represents the point of a position on the x-axis, which is also an array, the first element represents the X-coordinate, and all subsequent elements represent the y-coordinate.

(2) Data-data: Similar to the above type, the difference is that the second element of the numerical array represents the X-coordinate, followed by the y-coordinate, and the first element is just a label.

(3) Data-data-error: Similar to Data-data, the difference is that there are two elements behind his numerical array that represent error_plus and error_minus, such as

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

B.setdatavalues ($which _DV): Assigns an array $which_dv to a variable $this->data_values of a class. This function is called before it starts drawing.

C.setplottype ($which _pt): Set the type of chart, can be bars,lines,linepoints,area,points,pie and so on.

D.seterrorbarlinewidth ($WD): Sets the width of the error bar.

E.setfileformat ($which _file_format): Set the output of the image file format, can be gif,png,jpeg and so on. Still have to see your GD library whether support.

F.setusettf ($which _ttf): Set whether to use TTF, if you compile PHP support TTF, use Setusettf ("1"), otherwise set to 0.

2. Display function: Display image set output chart using the type of line, width and other parameters, you can also set the axis scale spacing, chart size and so on.

A.seterrorbarshape ($which _ebs): Sets the type of the precision line, either lines or tee, and if tee, the half degree of the T-line is set to Seterrorbarsize.

B.seterrprbarsize ($which _ebs): Sets the width of the precision line.

C.sethoriztickincreament ($which _ti): Sets the X-axis display scale spacing.

D.sethorizticks ($whick _nt): Sets the X axis to display the number of ticks. (Cannot and Sethoriztickincreament)

E.setnumvertticks ($which _nt): Sets the X axis to display the number of ticks. (Cannot and Setverttickincreament)

F.setplotarearpixels ($x 1, $y 1, $x 2, $y 2): Set chart size.

G.setpointshape ($which _pt): Set fixed-point shape: Rect,circle,diamond,triangle,dot,line,halfline.

H.setpointsize ($whick _ps Tutorial): Set the width of the point.

I.setprecisionx ($whick _prec): Sets the accuracy of the x axis. $whick _prec represents the number of digits after the decimal point.

J.setprecisiony ($whick _prec) sets the y-axis precision. $whick _prec represents the number of digits after the decimal point.

K.setsjading ($whick _s): Sets the width of the shadow.

L.setticklength ($which _tl): Sets the length of the marker line on the axis, in pixel.

M.settile ($title): Sets the title of the chart.

N.setverttickincreament ($whick _ti): and Sethorizticks ($whick _nt) are used to set the vertical and horizontal spacing of the marker lines on the axis.

O.setxdatalabelmaxlength ($which _XDLM): Sets the maximum length of the label on the X axis.

P.setxgridlabeltype ($which _XTF): Sets the X-axis label type, which can be time,title,data,none or default.

(1). Time: Set by Function strftime ().

(2). Title: Text type.

(3). Data: Format a number with a function number_format ().

(4). None: No Labels.

(5). Default: Output in the form of input.

3. Color function: The color function is used to set the display color of the elements in the chart, including the image background color, the color of the strikethrough line, the title color and so on!

A.setbackgroundcolor ($which _color): Sets the background color of the entire image.

B.setgridcolor ($which _color): Sets the color of the gridline.

C.setlegend ($which _legend): A parameter is an array of text whose contents are displayed in a column box.

D.setlegendpixels ($which _x, $which _y, $which _type): Sets the coordinates of the lower left corner of the frame, and the last parameter is available later.

E.setlightgridcolor ($which _color): The cut line has two colors, and this function sets one of them.

F.setlinewidth ($which _lt): Sets the line width used in the chart, and he also affects the width of the precision line.

G.setlinestyles ($which _sls): Sets the type of line, can be a solid line or dashed lines.

H.setplotbgcolor ($which _color): Sets the color of the area set using the Setplotareapixels () function.

I.settextcolor ($which _color): Sets the color of the text, which is black by default.

J.settickcolor ($which _color): Sets the color of the line engraved on the axis.

K.settitlecolor ($which _color): Sets the title color.

Looking at an instance, the code that generates the graphic above is as follows:

The code is as follows: # Phplot Demo

# 2008-01-09 LJB

# for more information-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 would 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 is not as.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.