Configuration and statistical charts of the PHP jpgraph Library: line chart, bar chart, pie chart, and jpgraph line chart

Source: Internet
Author: User

Configuration and statistical charts of the PHP jpgraph Library: line chart, bar chart, pie chart, and jpgraph line chart

Introduction to JpGraph

JpGraph is an open-source PHP Statistical Chart generation library. It is built based on the PHP GD2 graphics library and encapsulates operations related to generating statistical charts, hiding some complex operations, it makes it easier to output statistical charts on the PHP page. The official JpGraph website is: http://jpgraph.net, where developers can download the latest version of JpGraph for free and read the relevant help documentation or sample programs.

JpGraph Configuration

(1) modify the php. ini file.

Add the directory path of jpgraph in include_path, and change the name of the src directory after jpgraph is decompressed to jpgraph.

(2) Check whether PHP supports the GD library

Find the statement in the php. ini file; extension = php_gd2.dll. Remove the; sign before the preceding statement, that is, remove the comment. If you cannot find this statement because of different PHP versions, you can directly add extension = php_gd2.dll

(3) modify the jpgraph_gb2312.php File

Find the function: function gb2utf8 ($ gb)

Modify the function:

  function gb2utf8($gb) {  return $gb;  }

That is, the code that does not use gb2 encoding to convert to utf8.

Line chart

<? Php require_once ("jpgraph/jpgraph. php "); require_once (" jpgraph/jpgraph_line.php "); $ data1 = array (523,634,371,278,685,587,490,256,398,545,367,577); // array of the first curve $ graph = new Graph (500,300 ); $ graph-> SetScale ("textlin"); $ graph-> SetShadow (); $ graph-> img-> SetMargin (60, 30, 30, 70 ); // set the image margin $ graph-> graph_theme = null; // set the topic to null; otherwise, value-> Show (); $ lineplot1 = new LinePlot ($ data1) is invalid ); // create and set two curve objects $ lineplot 1-> value-> SetColor ("red"); $ lineplot1-> value-> Show (); $ graph-> Add ($ lineplot1 ); // place the curve on the image $ graph-> title-> Set ("CDN traffic diagram "); // Set the image title $ graph-> xaxis-> title-> Set ("month "); // Set the coordinate axis name $ graph-> yaxis-> title-> Set ("Gbits"); $ graph-> title-> SetMargin (10 ); $ graph-> xaxis-> title-> SetMargin (10); $ graph-> yaxis-> title-> SetMargin (10 ); $ graph-> title-> SetFont (FF_SIMSUN, FS_BOLD); // set the font $ graph-> yaxis-> title-> SetFont (FF _ SIMSUN, FS_BOLD); $ graph-> xaxis-> title-> SetFont (FF_SIMSUN, FS_BOLD ); $ graph-> xaxis-> SetTickLabels ($ gDateLocale-> get1_month (); $ graph-> Stroke (); // output image?>

Bar Chart

<? Php require_once ("jpgraph/jpgraph. php "); require_once (" jpgraph/jpgraph_bar.php "); $ data = array (96,145,); $ ydata = array (" 1 ", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11 ", "12"); $ graph = new Graph (500,300); // Create a new Graph object $ graph-> SetScale ("textlin "); // scale style $ graph-> SetShadow (); // set the shadow $ graph-> img-> SetMargin ); // set the margin $ graph-> graph_theme = null; // set the topic to null; otherwise, valu E-> Show (); invalid $ barplot = new BarPlot ($ data); // create a BarPlot object $ barplot-> SetFillColor ('Blue '); // set the color $ barplot-> value-> Show (); // set the display number $ graph-> Add ($ barplot ); // Add the bar chart to the image $ graph-> title-> Set ("CDN traffic diagram "); $ graph-> xaxis-> title-> Set ("month "); // Set the title and X-Y axis title $ graph-> yaxis-> title-> Set ("streaming (Mbits )"); $ graph-> title-> SetColor ("red"); $ graph-> title-> SetMargin (10 ); $ graph-> xaxis-> title-> SetMargin (5); $ graph-> xaxis-> S EtTickLabels ($ ydata); $ graph-> title-> SetFont (FF_SIMSUN, FS_BOLD); // set the font $ graph-> yaxis-> title-> SetFont (FF_SIMSUN, FS_BOLD); $ graph-> xaxis-> title-> SetFont (FF_SIMSUN, FS_BOLD); $ graph-> xaxis-> SetFont (FF_SIMSUN, FS_BOLD ); $ graph-> Stroke ();?>

Pie Chart

<? Php require_once ("jpgraph/jpgraph. php "); require_once (" jpgraph/jpgraph_pie.php "); require_once (" jpgraph/once "); $ data = array ); $ graph = new PieGraph (550,500); $ graph-> SetShadow (); $ graph-> title-> Set ("CDN traffic ratio "); $ graph-> title-> SetFont (FF_SIMSUN, FS_BOLD); $ pieplot = new PiePlot3D ($ data); // create a PiePlot3D object $ pieplot-> SetCenter (0.4, 0.5 ); // set the pie chart center position $ p Ieplot-> SetLegends ($ gDateLocale-> get1_month (); // set the legend $ graph-> Add ($ pieplot); $ graph-> Stroke ();?>

The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!

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.