Linux.com

Feature

Create Flash charts with PHP/SWF Charts

By Mayank Sharma on April 05, 2006 (8:00:00 AM)

Share    Print    Comments   

PHP/SWF Charts brings interactive eye candy to your charts and graphs. This PHP tool generates 20 types of charts, including line, column, 3-D column, pie, 3-D pie, bar, scatter, and polar charts.

Rather than creating simple images, PHP/SWF Charts outputs Flash movies, which you can view in a browser that's running at least version 6 of Adobe Flash Player. You can click and drill down on the charts, which feature animated transitions and present values on mouse hover. You can update the charts with live data without reloading the page.

PHP/SWF Charts isn't an open source tool, but you can download it for free and use it with certain restrictions. Simply download one of the three archives (around 164KB each), unzip it, and place charts.swf, charts.php, and the charts_library/ directory on your Web server.

Now you're ready to start charting. Say you want to create a chart that plots users' display resolution according to W3Schools' browser statistics. Use this code to generate the chart:

//browser_chart.php -- Creates the chart

<?php
include "charts.php";

//setting the chart's attributes
$chart[ 'axis_value' ] = array ( 'max'=>60, 'font'=>"arial", 'bold'=>true, 'size'=>10 );
$chart[ 'draw' ] = array ( array ( 'type'=>"text", 'rotation'=>-90, 'bold'=>true, size=> '22', 'x'=>10, 'y'=>230, 'width'=>300, 'height'=>200, 'text'=>"Display Resolutions", 'h_align'=>"left", 'v_align'=>"top" ),
array ( 'type'=>"text", 'color'=>"000033", 'alpha'=>50, 'font'=>"arial", 'rotation'=>-90, 'bold'=>true, 'size'=>12, 'x'=>7, 'y'=>210, 'width'=>300, 'height'=>55, 'text'=>"(per 100 visits)", 'h_align'=>"center", 'v_align'=>"middle" ) );
//throwing in the data
$chart ['chart_data'] = array ( array ( "",         "2003", "2004", "2005", "2006" ),
                                  array ( "640x480",     2,     1,     0,     0  ),
                                  array ( "800x600",   47,     37,     30,     20  ),
                                  array ( "1024x768",    40,     47,      53,     57  ),
                                  array ( "Higher",     6,      10,     12,     17 ),
                                  array ("Unknown",     5,      5,      5,      6),
                                );

//send the data to charts.swf
SendChartData ( $chart );
?>

In this file, you specify the data you need the chart to plot. The chart can take data through PHP variables, as shown, or from a database. You also specify the various attributes of the chart, including its type, color, and axis information. The Tutorial and Reference sections on the project's Web site explain the attributes in detail.

Now create a file that displays the chart inside a Web page:

//display_chart.php -- Displays the chart

<HTML>
<BODY bgcolor="#FFFFFF">

<?php

//include charts.php to access the InsertChart function
include "charts.php";


//include the flash file, the charts library and the php file that has the chart details
echo InsertChart ( "charts.swf", "charts_library", "browser_chart.php" );


//footer information
echo "<p><font size=-10>source: <a href=\"http://www.w3schools.com/browsers/browsers_stats.asp\">W3C Browser Statistics</a></font></p>";
?>

</BODY>
</HTML>

This file can also be an HTML document if you've configured your server to process PHP inside HTML pages.

That's all there is to it. If you still aren't impressed, take a look at the gallery of charts you can create using PHP/SWF Charts.

Share    Print    Comments   

Comments

on Create Flash charts with PHP/SWF Charts

Note: Comments are owned by the poster. We are not responsible for their content.

Where I stopped reading...

Posted by: Anonymous Coward on April 05, 2006 06:42 PM
"PHP/SWF Charts isn't an open source tool", that is where I read until I stopped reading the article.

Also SWF is just annoying resource hogging dumb stuff and I dont even see the point of use it for diagrams and stuff.
I would prefer PNG image files.

#

Re:Where I stopped reading...

Posted by: Anonymous Coward on April 05, 2006 08:55 PM
OSS fanatics often amaze me; they'd just as soon die of thirst in the desert, than to drink a cup of water that wasn't "free".

Software is good because it is useful, not because its source is available.

Sure, write something better (if you can) that includes the source. But religion about the source being available or not is hardly relevant to the topic of this software's usefulness, or people's need to know of its existence.

#

Re:Where I stopped reading...

Posted by: Anonymous Coward on April 05, 2006 09:14 PM
This is nothing more than an advert and your defending it.

#

Re:Where I stopped reading...

Posted by: Shashank Sharma on April 05, 2006 11:42 PM
Not one to get into flame wars, but here goes...

I see nothing wrong with this article. It is nice and it is useful. When you need to get work done, it doesn't matter what software you use - it should work.

I know I shouldn't be doing this but... people who don't even care to give their name when writing comments and especially those who don't even know the difference between 'your' and 'you are' are really not the kind whose opinions matter to anyone.

#

Re:Where I stopped reading...

Posted by: Anonymous Coward on April 06, 2006 03:04 AM
According to your reasoning, using M$ products is okay too, right? Try writing about "open tools/technologies" (e.g., SVG) that people can use. Don't just submit articles to make some cash from NewsForge!

#

Re:Where I stopped reading...

Posted by: Anonymous Coward on April 06, 2006 03:07 AM
Fanatic.

#

I stopped even before!

Posted by: Anonymous Coward on April 05, 2006 10:18 PM
Flash is not only proprietary (which is a show-stopper for me too) but a piece of sh*t thing to begin with. I would not even use a "free flash"<nobr> <wbr></nobr>...
Having a non-free tool to create a non-free application us such typical NewsForge corporate brown-nosing that it makes me wonder why I even bother to read their stuff at all

#

Hey NewsForge - what this crap doing here?

Posted by: Anonymous Coward on April 05, 2006 10:21 PM
I know. You are not "free software zealots" or anything has horrible. You are the moderate, pragmatic and suit-compatible (and sponsored) "Open Source" newspaper. Bravo!

But what is this crap article about a non-free, oops, sorry, non-open source application to develop non-free, oops again, I meant non open source products doing here?

Are you THAT desperate for corporate approval?

Is your next "open source" article going to be "how to create mp3s on OSX"?

Pathetic

#

proprietary garbage

Posted by: Anonymous Coward on April 06, 2006 12:53 AM
If you happen to know of an open source tool for making SVG graphs with Python and XML, that would be appreciated.

#

well, Shareware it is...

Posted by: Anonymous Coward on April 06, 2006 09:08 AM
but unlike the other commentors here, I'm not seeing anything wrong with that. If the article does anything, then provoking someone to write an open source (or Free software) alternative. -- Not that we didn't already have PHP chart libraries of one flavour or the other...

#

Pain

Posted by: Anonymous Coward on May 30, 2006 01:22 AM
[URL=http://nervepainrelief.jeeran.com/painrelief<nobr>.<wbr></nobr> htm] Nerve pain relief [/URL]

  [URL=http://www.back.painreliefnetwork.net/lowbac<nobr>k<wbr></nobr> pain.htm] Low back pain [/URL]

  [URL=http://blog.gala.net/uploads/painreliefback/<nobr>b<wbr></nobr> ackpainrelief.htm] Back pain relief [/URL]

  [URL=http://www.weblog.ro/usercontent/13155/profi<nobr>l<wbr></nobr> es/kneepainrelief.htm] Knee pain relief [/URL]

  [URL=http://www.info.painreliefnetwork.net/Pain-R<nobr>e<wbr></nobr> lief.html] Pain relief [/URL]

  [URL=http://www.sitefights.com/community/scifi/pa<nobr>i<wbr></nobr> nrelief/painreliefpreved.htm] Pain relief [/URL]

  [URL=http://www.info.painreliefnetwork.net/Medica<nobr>t<wbr></nobr> ion-Pain-Relief.html] Medication pain relief [/URL]

  [URL=http://www.info.painreliefnetwork.net/Natura<nobr>l<wbr></nobr> -Pain-Relief.html] Natural pain relief [/URL]


  [URL=http://painrelief.fanspace.com/index.htm] Pain relief [/URL]

  [URL=http://lowerbackpain.0pi.com/backpain.htm] Back Pain [/URL]

  [URL=http://painreliefproduct.guildspace.com] Pain relief [/URL]
[URL=http://painreliefmedic.friendpages.com] Pain relief [/URL]

#

Not Good Stuff

Posted by: Anonymous Coward on April 10, 2006 03:37 AM
I am using AMD64, so I cannot even get Flash. It still isn't open anyway, so I would not use it, even if I could. Why not encourage an open Flash from Adobe?

#

Pain

Posted by: Anonymous Coward on May 30, 2006 01:21 AM
[URL=http://nervepainrelief.jeeran.com/painrelief<nobr>.<wbr></nobr> htm] Nerve pain relief [/URL]
[URL=http://www.back.painreliefnetwork.net/lowbac<nobr>k<wbr></nobr> pain.htm] Low back pain [/URL]
[URL=http://blog.gala.net/uploads/painreliefback/<nobr>b<wbr></nobr> ackpainrelief.htm] Back pain relief [/URL]
[URL=http://www.weblog.ro/usercontent/13155/profi<nobr>l<wbr></nobr> es/kneepainrelief.htm] Knee pain relief [/URL]
[URL=http://www.info.painreliefnetwork.net/Pain-R<nobr>e<wbr></nobr> lief.html] Pain relief [/URL]
[URL=http://www.sitefights.com/community/scifi/pa<nobr>i<wbr></nobr> nrelief/painreliefpreved.htm] Pain relief [/URL]
[URL=http://www.info.painreliefnetwork.net/Medica<nobr>t<wbr></nobr> ion-Pain-Relief.html] Medication pain relief [/URL]
[URL=http://www.info.painreliefnetwork.net/Natura<nobr>l<wbr></nobr> -Pain-Relief.html] Natural pain relief [/URL]


[URL=http://painrelief.fanspace.com/index.htm] Pain relief [/URL]
[URL=http://lowerbackpain.0pi.com/backpain.htm] Back Pain [/URL]
[URL=http://painreliefproduct.guildspace.com] Pain relief [/URL]
[URL=http://painreliefmedic.friendpages.com] Pain relief [/URL]

#

Meaw

Posted by: Anonymous [ip: 192.168.200.233] on October 19, 2007 06:56 AM
love gag

#

Create Flash charts with PHP/SWF Charts

Posted by: Anonymous [ip: 213.115.91.226] on January 03, 2008 12:53 PM
I was going to use this for a project, but I've since chosen another library, since PHP/SWFCharts doesn't handle certain umlauts (åäö etc). It bugs out completely if any of those chars are in a variable, and it doesn't handle ¨aut; or #382-style substitution either.

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya