Home >Backend Development >PHP Tutorial >Detailed explanation of how phplot generates image classes_PHP tutorial
Detailed explanation of the picture class generated by lot in the php tutorial
I personally use phplot, which is an automatically generated class written using the image function of php. First of all, I only know about it. In the original Some versions of it seem to require various configurations and support, but now they all use the php5 series. Everyone only needs to understand some commonly used functions, just like when we learn a software, we only need to know how to use it. If you are interested, you can study it in depth, but for most of our friends, as long as you can use it, it is fine. After all, it is not commonly used. It is only used when you need to use PHP to draw pictures. So we just need to know how to use it, then
we must know the role of its function, just like when we learn discuz, we just need to know how to use it!
The download address of phplot is http://www.sourceforge.net/projects/phplot/The latest version seems to be phplot5.0
His commonly used functions are divided into several categories: configuration function, display function, color Function
1. Configuration function: configure what type phplot uses and how to display the image.
a.SetDataType($which_dt): Set the data type used. Multiple types can be used in this.
(1)text-date: The data is arranged at equal intervals along the x-column. Each array element represents a point at a certain position on the x-axis. It is also an array. The first element represents the x coordinate, and all subsequent elements of
represent the y coordinate.
(2) data-data: Similar to the above type, except that the second element of the numerical array represents the x coordinate, the following element represents the y coordinate, and the first element is just a label.
(3)data-data-error: Similar to data-data, except that there are two elements after its numerical array representing error_plus and error_minus, such as
(data_labl,x_position,y_position,error_plus,error_minus ).
b.SetDataValues($which_dv): Assign an array $which_dv to a variable $this->data_values of the class. This function should be called before starting to draw.
c.SetPlotType($which_pt): Set the type of chart, which can be bars, lines, linepoints, area, points, pie, etc.
d.SetErrorBarLineWidth($wd): Set the width of the error bar.
e.SetFileFormat($which_file_format): Set the format of the output image file, which can be GIF, PNG, JPEG, etc. It also depends on whether your GD library supports it.
f.SetUseTTF($which_ttf): Set whether to use TTF. If the compiled php supports TTF, use SetUseTTF("1"); otherwise set to 0.
2. Display function: Display image sets the type, width and other parameters of the lines used in the output chart. You can also set the spacing of the coordinate axis scales, the size of the chart, etc.
a.SetErrorBarShape($which_ebs): Set the type of precision line, which can be line or tee. If it is tee, the half degree of the T-shaped line is set to SetErrorBarSize.
b.SetErrprBarSize($which_ebs ): Set the width of the precision line.
c.SetHorizTickIncreament($which_ti): Set the spacing of the x-axis display scale.
d.SetHorizTicks($whick_nt): Set the number of ticks displayed on the x-axis. (Cannot be used with SetHorizTickIncreament)
e.SetNumVertTicks($which_nt): Set the number of ticks displayed on the x-axis. (Cannot be used with SetVertTickIncreament)
f.SetPlotArearpixels($x1,$y1,$x2,$y2): Set the chart size.
g.SetPointShape($which_pt): Set the shape of the fixed point: rect, circle, diamond, triangle, dot, line, halfline.
h.SetPointSize ($whick_ps tutorial): Set the width of the point.
i.SetPrecisionX($whick_prec): Set the precision of the x-axis. $whick_prec represents the number of digits after the decimal point.
j.SetPrecisiony($whick_prec) sets the precision of the y-axis. $whick_prec represents the number of digits after the decimal point.
k.SetSjading($whick_s): Set the width of the shadow.
l.SetTickLength($which_tl): Set the length of the marker line on the coordinate axis, in pixels.
m.SetTile($title): Set the title of the chart.
n.SetVertTickIncreament($whick_ti): and SetHorizTicks($whick_nt) are two functions used to set the vertical and horizontal intervals of the mark lines on the coordinate axis.
o.SetXDataLabelMaxlength($which_xdlm): Set the maximum length of the label on the x-axis.
p.SetXGridLabelType($which_xtf): Set the label type of the x-axis, which can be time, title, data, none or default.
(1).time: Set by the function strftime().
(2).title: text type.
(3).data: Use the function number_format() to format numbers.
(4).none: No tags.
(5).default: Output according to the input form.
3. Color function: The color function is used to set the display color of each element in the chart, including the image background color and the color of the grid line. Title colors and more!
a.SetBackgroundColor($which_color): Set the background color of the entire image.
b.SetGridColor($which_color): Set the color of the grid line.
c.SetLegend($which_legend): The parameter is a text array, and its content is displayed in a chart box.
d.SetLegendPixels($which_x,$which_y,$which_type): Set the coordinates of the lower left corner point of the picture frame. The last parameter will be available later.
e.SetLightGridColor($which_color): The cutting line has two colors. This function sets one of them.
f.SetLineWidth($which_lt): Sets the line width used in the chart. It also affects the width of the precision line.
g.SetLineStyles($which_sls): Set the type of line, which can be solid or dashed.
h.SetPlotBgColor($which_color): Set the color of the area set using the SetPlotAreaPixels() function.
i.SetTextColor($which_color): Set the color of the text, the default is black.
j.SetTickColor($which_color): Set the color of the tick line on the coordinate axis.
k.SetTitleColor($which_color): Set the title color.
Look at an example
The code to generate the above graphic is as follows:
# 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();
怎么样,不错吧。。 喜欢的朋友可以到 http://phplot.sourceforge.net/ 官方站下载