Application example: PHP generates a pChart (with source code) _ PHP Tutorial

Source: Internet
Author: User
Application example: PHP generates a pChart (with source code ). PChart is an open-source chart generation Library, mainly involving three classes: pChart. class, pData. class, pCache. class, which can generate more than 20 simple or complex charts. pChart is an open-source chart generation library that supports the PN help house tutorial. it mainly involves three classes: pChart. class, pData. class, pCache. class, which can generate more than 20 simple or complex charts. it supports PNG, JPG, and GIF common image formats. The data source can be from Database, CSV, or hand-written. To use this PHP program, you need to enable the GD service. let's take a look at the workflow of pChart:

  

There are three main steps:

  1. * Reading is used to generate chart data (databases and files)
  2. * Design chart styles (rounded corners, background colors, etc)
  3. * Create tags, questions, and legends and generate charts

Here is a simple bar chart:

  

The code is as follows:

// Standard comprehensions
Include ("pChart/pData. class ");
Include ("pChart/pChart. class ");

// Dataset definition
$ DataSet = new pData;
// Chart data
$ DataSet-> AddPoint (array (,-3,-3, 3, 4), "Serie1 ");
$ DataSet-> AddPoint (array (,-, 3), "Serie2 ");
$ DataSet-> AddPoint (array (, 2,-1,-4,-,), "Serie3 ");
$ DataSet-> AddAllSeries ();
$ DataSet-> SetAbsciseLabelSerie ();
// Data legend
$ DataSet-> SetSerieName ("Microsoft", "Serie1 ");
$ DataSet-> SetSerieName ("IBM", "Serie2 ");
$ DataSet-> SetSerieName ("Google", "Serie3 ");

// Initialise the graph
$ Test = new pcharts (700,230 );
// Set the chart size and style
$ Test-> setFontProperties ("Fonts/tahoma. ttf", 8 );
$ Test-> setGraphArea (680,200, 30 );
$ Test-> drawFilledRoundedRectangle (693,223, 5,240,240,240 );
$ Test-> drawRoundedRectangle (695,225, 5,230,230,230 );
$ Test-> drawGraphArea (255,255,255, TRUE );
$ Test-> drawScale ($ DataSet-> GetData (), $ DataSet-> getdatadeworkflow (), SCALE_NORMAL, 150,150,150, TRUE, TRUE );
$ Test-> drawGrid (4, TRUE, 230,230,230, 50 );

// Draw the 0 line
$ Test-> setFontProperties ("Fonts/MankSans. ttf", 6 );
$ Test-> drawTreshold (0,143, 72, TRUE, TRUE );

// Draw the bar graph
// Use drawBarGraph () for the column chart ()
$ Test-> drawBarGraph ($ DataSet-> GetData (), $ DataSet-> getdatadeworkflow (), TRUE, 80 );


// Finish the graph
// Create attributes such as Legend, title, and font
$ Test-> setFontProperties ("Fonts/MankSans. ttf", 10 );
$ Test-> drawLegend (596,150, $ DataSet-> getdatadeworkflow (), 255,255,255 );
$ Test-> setFontProperties ("Fonts/MankSans. ttf", 10 );
$ Test-> drawTitle (50, 22, "Example", 50, 50, 50,585 );

// Generate a chart
$ ImageFile = "example12.png ";
$ Test-> Render ($ imageFile );
Echo '';
?>

  • Three pages in total:
  • Previous Page
  • 1
  • 2
  • 3
  • Next page

PChart is an open-source chart generation Library, mainly involving three classes: pChart. class, pData. class, pCache. class, can generate more than 20 simple or complex charts, supports PN...

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.