Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Jpgraph for PHP graphic operation

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to use Jpgraph for PHP graphics operations. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The details are as follows:

1. Jpgraph installation and configuration

Download the Jpgraph installation package

Put it on disk after decompression (preferably with the web page)

Modify the php.ini file:

1. Memory memory_limit=X, at least 32m

2. Execution time max_execution_time=X, it takes more time for complex images to load, and make corresponding modifications according to the complexity of the images.

3. Cache output_buffering comments out cache to facilitate debugging

2. Basic steps for creating graphics using Jpgraph (necessary)

1. Include the required class library files

Require_once ()

2. Initialize data

$data=array ()

It can be fixed data in php program, that is, static data, which can be obtained directly.

Can be data stored in a text file

It can be data stored in the database

Can be data passed through the URL parameter (GET or POST)

3. Create an instance of Graph class

$graph=new Graph ()

You can set the size of the drawing here

4. Set the content of the title, x-axis title, y-axis title, and its font, color, position, etc.

5. Create a corresponding diagram instance

It can be line chart, column chart, pie chart, 3D, etc.

6. Add data to the drawing

$graph- > Add ()

7. Display the picture

$graph- > Stroke ()

At this point, a simple figure is complete.

Note:

Chinese fonts are garbled

When displaying Chinese characters by default, Gpgraph encodes Chinese characters as gb2312 and converts them to utf-8 before displaying them. If the file is encoded in gb2312, you only need to set the first parameter of the SetFont () method to FF_SIMSUN.

If it is encoded by utf-8, you need to convert the coding of Chinese characters to gb2312 first, so that the Chinese characters can be displayed normally.

Iconv ("UTF-8", "gb2312", $x) can be used for transcoding.

Some common methods:

$graph- > title- > Set ('set the title of the chart'); $graph- > tabtitle- > Set ('set the picture header text'); $graph- > xaxis- > title- > Set ("set the title of the X axis"); $graph- > yaxis- > title- > Set ("set the title of the Y axis"); $graph- > SetScale ('textlin'); / / set the scale type $graph- > img- > SetMargin (50, 40, 40, 55); / / frame spacing (left and right) $graph- > title- > SetFont (FF_SIMSUN,FS_BOLD,12) / / title font $graph- > xaxis- > title- > SetFont (FF_SIMSUN,FS_BOLD,10); $graph- > xaxis- > title- > SetFont (FF_SIMSUN,FS_BOLD,10); $graph- > xaxis- > SetFont (FF_SIMSUN,FS_BOLD,12); / / typeface on the coordinate column $graph- > yaxis- > SetFont (FF_SIMSUN,FS_BOLD,12); $graph- > title- > SetColor ('red'); / / title color $graph- > xaxis- > title- > SetColor (' red'); $graph- > yaxis- > title- > SetColor ('red') $graph- > xaxis- > title- > SetMargin (20); / distance from the axis $graph- > yaxis- > title- > SetMargin (20); / distance from the Y axis $linepot- > SetColor ('red'); / / the color of the line (line chart) $linepot- > SetWeight (2); / / width of the line $linepot- > value- > SetFormat ('% 0.1f'); / / formatted value $linepot- > value- > show (true); / display value $graph- > SetBackGroundImage (); set background $graph- > SetMarginColor ('lightblue') / / set graphic color $graph- > SetShadow (); / / $graph- > Set3DPerspecttive (); / / set 3D effect map / * Tilt 3D effect 1, 'SKEW3D_UP' 2, 'SKEW3D_DOWN' 3,' SKEW3D_LEFT' 4, 'SKEW3D_RIGHT'*/$p1- > SetTheme (' water'); / / set style $p1-> SetCenter (0.5 Magazine 0.55); / / set graphic position $graph- > legend- > Pos (0.1Magin0.9) / / set the location of the comment text $graph- > legend- > SetFont (FF_SIMSUN,FS_BOLD,12); / / set the font of the note text. Thank you for reading! This is the end of this article on "how to use Jpgraph for PHP graphics operation". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report