Add Graphs To Your PHP Web App With pChart

Compare Cost: Get 8 Free E-Commerce Design Bids
Service:
Location:
Budget:
Deadline:
Compare: Web Design Calculator | Web Design Cost Guidelines

Are you an E-Commerce Web Designer? Add a Free Listing

php graphspChart is a remarkably advanced graphing toolkit for PHP. It’s free under GPL licence, highly customisable, fully object oriented, and more than capable of handling any data you throw at it. Let me show you how to get started with using it for your web app.

This tutorial assumes a basic knowledge of PHP.

Features – At a Glance

Getting Started

Download the latest pChart package and upload it to the root of your web server. Rename the direct to pChart. You can test it out right away by navigating to this directory which will load the example graphs.
php graphs

Try it Yourself

To learn the basic method of drawing a graph, create a new PHP file in the root of your server called test.php. Add these lines to the top (assuming the directory you upload pChart to named just pChart):

/* Include all the classes */
include("pChart/class/pDraw.class.php");
include("pChart/class/pImage.class.php");
include("pChart/class/pData.class.php");

The next step is to create a dataset, and use the addPoints method.

/* Create your dataset object */
$myData = new pData();
/* Add data in your dataset */
$myData->addPoints(array(VOID,3,4,3,5));

Notice that you can use a VOID keyword if data is missing. You could also connect to a MySQL data source and pull an array of data from there, or load a CSV file from somewhere. We’re going to be drawing a very simplistic graph ofcourse, but you can also add multiple datasets, adjust ticks etc at this point.

Next you need to create the image object, set the graphing area, and choose a font.

$myPicture = new pImage(700,230,$myData); // width, height, dataset
$myPicture->setGraphArea(60,40,670,190); // x,y,width,height
$myPicture->setFontProperties(array("FontName"=>"pChart/fonts/verdana.ttf","FontSize"=>11));

The scale must then be computed before output – but this can be done automatically – then draw the graph, like this:

$myPicture->drawScale();
$myPicture->drawSplineChart();

In this case, we’re drawing a spline chart – basically a curved line chart – but there’s a huge list of other charts you can draw just by changing this function. The very last step is to output the resulting PNG file to the browser. Use the Stroke() function to do this:

$myPicture->Stroke();

You’d use this in cases where you’re either displaying directly to the user, or embedding the PHP as file as an image, like:

<img src="test.php">

If you load the test.php in your browser now, you should see something similar to this:

php graphs

Another option is to render the graph to a file if you’re generating them through some kind of automated CRON job, for instance. In that case, use (where the path of the image is relative to the test.php and in a writeable folder):

$myPicture->render("mypic.png");

Alternatives

Though pChart is the most comprehensive charting toolbox for PHP by far, there are some alternatives:

That’s it from me this time, I do hope you have a play with pChart in web apps you’re making. I’ve just started working it into the web side of my Egg Counter iPhone application, so I’m certainly no expert on it yet. I’ll try to point you in the right direction if you have any questions, but there’s also extensive documentation available. Do you have a better way of graphing data in your web apps? Let us know!


Source http://www.makeuseof.com/?p=99748
Sun, 19 Feb 2012 18:30:28 GMT
Tags: charts, graphs, How-To Articles, php, tutorials,
Grayslake E-Commerce | New Rochelle E-Commerce | Shreveport E-Commerce | Marina del Rey E-Commerce | Manchester E-Commerce | NOIDA E-Commerce | Oakland E-Commerce | Clovis E-Commerce | Chicago E-Commerce | Teaneck E-Commerce |

charts


graphs


How-To Articles


How To Easily Synchronize Folders Outside Dropbox Using Symlinks

There’s a long running discussion on Quora that grabbed my attention. The topic is about the reason why Dropbox is more popular than other free programs with similar functionality. The various answers boiled down to this: simplicity. You put your fi

How to Scan a Reformatted Hard Drive to Recover Files

I think everyone has had that sinking feeling when you realize you’ve just made a very…big…mistake. Accidentally reformatting and/or installing a new operating system on the wrong hard drive is one of those things you could do to trigger

How To Set Up Your Own FTP Server With Core FTP

There is one thing that I do almost constantly during my day job that I realized I don’t really do at home. That is creating an FTP server where you can retrieve files from within one sub-network while you’re anywhere on a LAN, or in the case


Need E-commerce Design? Check out our member profiles:

Hampton
Stockbridge Web Design  Profile
Stockbridge Web Design

We provide web & graphic design, programming, marketing and business consulting services throughout the globe.

Hampton, Georgia US
Oklahoma City
WebAdaptions.com Profile
WebAdaptions.com

Web site design and development-eCommerce,customer management systems,SharePoint 2010,customer relationship management,product lifecycle management,supply chain management,extranet,intranet

Oklahoma City, Oklahoma US
Rio Rancho
TGS Web Design SEO Albuquerque Profile
TGS Web Design SEO Albuquerque

Ecommerce web design SEO Albuquerque - Website Design Web Hosting Services

Rio Rancho, New Mexico US
Covington
Covington Web Design  Profile
Covington Web Design

Providing Website Design, Ecommerce Website Design(Online Stores), Graphic Design, Web Hosting, SEO, Web Development/Programming, DNS Hosting,in Covington, GA and everywhere else.

Covington, Georgia US
Saddle Brook
Greenrack Profile
Greenrack

Providing best services in affordable prices. Shopping cart setup, payment gateway integration, designing, and customization for all types of businesses and individuals. Contact now.

Saddle Brook, New Jersey US
Wiley Park
Dzino web development Profile
Dzino web development

Dzino Web Development provide Website Design, Graphics, Web & Flash animation, Website Development including Ecommerce

Wiley Park, New South Wales AU
Santa Barbara
Peter Otte Productions LLC Profile
Peter Otte Productions LLC

Founded in January, 2000, Peter Otte Productions is a professional graphic and web design firm that delivers custom ecommerce sites.

Santa Barbara, California US
Brookhaven
Laughing Man Design Profile
Laughing Man Design

Specializing in e-Commerce, Content Management Systems, Graphic Design and SEO Services.

Brookhaven, Pennsylvania US



Get Free Logo Design Quotes






How Big Is the Internet? [Infographic]

Did you know there are more iPhones sold than babies born Check out this and a whack of other amazi



Cool Tech Deals Of The Week – Samsung UN55D6400 55in 3D LED LCD HDTV (1080p, 120Hz) $1299.99 & More!

TigerDirect has the Samsung UN55D6400 55 LED LCD HDTV for a low 1299 99 and free shipping For mor



Hot Tech Deals – XFX Radeon HD 4650 1GB PCi-E Low Profile Video Card $14.99AR Free Shipping & More!

Newegg has the XFX HD 465X ZNL2 Radeon HD 4650 1GB 128 Bit DDR2 Low Profile Video Card for a low 14



New Apple Store To Open In Grand Central Terminal Today [News]

A new flagship Apple Store is scheduled to open up in the Big Apple more specifically Grand Centra



30 Shots of Incredible Airplane View Photography

img src http rss buysellads com img php z 1264761 k bb78eac5744533b69852b62261051c57 a 1226



20 Awesome Flash Templates From Flashmo

Are you looking for a good flash templates just be here for some time and you can go with your temp



Cool Websites and Tools [December 19th 2011]

Check out some of the latest MakeUseOf discoveries Most of the listed websites are FREE or come wit




Design Leads

Article Tags
E-commerce Design Articles
Web Apps & Internet (374)
News (291)
Web Apps (129)
Inspiration (128)
Music (119)
iPhone / iPad / iPod (116)
cool web apps (108)
Google Android (101)
Mobile Tips (100)
Announcements (99)
deals (88)
Games & Gaming Tips (84)
Tech Deals (82)
Opinion & Polls (76)
Cool Software Apps (76)
Social Media (66)
iOS (66)
Browser Tips & Tricks (66)
iPhone Apps (59)
Freebies (58)
geeky fun (58)
Photography (58)
iphone (55)
Google (53)
troubleshoot (53)
android (52)
Photoshop (52)
Graphics (51)
facebook (50)
How-To Articles (50)

Friends:
E-Commerce Website Pricing
Web Design Quote
Website Design
Graphic Designers


E-commerce Design Valid HTML 4.0 Transitional Valid CSS!