homepage Welcome to WebmasterWorld Guest from 54.227.5.234
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
including scatter graph on report.
help me get started?
deejay




msg:3931626
 10:29 pm on Jun 11, 2009 (gmt 0)

So I have a pretty complex report which ranks the productivity of a client's widgets against the productivity of all our other clients comparable widgets.

aw hell, widgets isn't going to work well here - it's an agricultural base, so i'll use veges, ok?

So the client can choose whether he wants to evaluate a single paddock, or a property, or his whole farming operation, - at paddock level it's a single report for one type of product, taking out to a property level, he might grow a dozen different types of produce, so the report has a dozen pages, with organic apples being compared only to organic apples, and conventional lettuces to conventional lettuces.

The original version of this report I built in access and I had at the top of each page a scatter graph, showing productivity/profitability of all the comparison growers in blue, and the current grower in red. Very visual, very intuitive.

I have the body of the report built in php, and can readily put the required XY values into an array, but then the question is how do I build the graph.

I've looked around graphing scripts this morning, including phplot and various GD Library applications, and the one thing they seem to have in common is that they need to be on a page of their own, rather than being able to be integrated into the report. Surely this can't be the case - I've tried putting a sample graph on its own page and using an include to bring it into the report, but I just get headers already sent errors.

I'd appreciate it greatly if someone could help me get this kicked off. Perhaps it's not even php I should be looking at - javascript maybe? of course I don't know javascript at all really, so it would need to be a fairly self-contained script.

so in short, what I need:

a scatter graph that can support two data series.
can be embeded/included in a php page.
dynamic.
can be repeated with a new data series as many times as required within the report.

 

deejay




msg:3931724
 2:36 am on Jun 12, 2009 (gmt 0)

Alright, Progress. I think.

I have php/swf installed and working. The question is the most efficient way to get the data into the script.

At present I have a test graph displaying on my report page as follows:

a.php = main report page with mysql query laying out tabular data and an include/echo bringing in the graph, as per the maani.us instructions.

include "charts.php";
echo InsertChart ( "charts.swf", "charts_library", "b.php", 400, 300, "e4e4e4" );

b.php = the included chart, currently using a default sample array of data:

<?php

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

//change the chart to a bar chart
$chart['chart_type'] = "scatter";

$chart['chart_pref'] = array ('point_size'=>5, 'point_shape'=>"circle", 'trend_thickness'=>0, 'trend_alpha'=>0, 'line_thickness'=>0, 'line_alpha'=>0);

$chart['chart_data'] = array ( array ( "", "x", "y", "x", "y", "x", "y", "x", "y", "x", "y" ),
array ( "region 1", 15, -5, 2, 8, 3, 7, 1.5, 6.5, 2.5, 2.5 ),
array ( "region 2", 1, 1, 3, 5, 2, -7, 3.7, 10.5, 3.5, 2.5 ));

SendChartData($chart);
?>

The query that generates the data required on the graph lives in a.php (the data is also displayed in a tabular form on the page). Presumably I could put a copy of the query in b.php (I'd still have to get the query delimiters from a.php to b.php), but it's a massive beast that I really don't want to have to repeat if possible.

The more practical option would certainly be to generate the chart data array in a.php and hand it to the graph from there.

With the sample data I have already tried moving the sample array above to a.php:


$chartdata = array ( array ( "", "x", "y", "x", "y", "x", "y", "x", "y", "x", "y" ),
array ( "region 1", 15, -5, 2, 8, 3, 7, 1.5, 6.5, 2.5, 2.5 ),
array ( "region 2", 1, 1, 3, 5, 2, -7, 3.7, 10.5, 3.5, 2.5 ));

and in b.php:


$chart['chart_data'] = $chartdata;

Didn't work.

Help? Bueller? Anybody?

deejay




msg:3931736
 3:27 am on Jun 12, 2009 (gmt 0)

DUH moment de jour: having the array available in a.php doesn't work because b.php isn't actually included on the page. It's called in the 'insertchart' function, but not included.

Which probably makes me worse off than better.

nick279




msg:3932151
 3:30 pm on Jun 12, 2009 (gmt 0)

deejay

I'd seriously recommend having a look at Fusion Charts - they have outstanding graphics and also a PHP class interface

I haven't had any issues with it so far, and generate all my data via XML

deejay




msg:3932536
 6:19 am on Jun 13, 2009 (gmt 0)

Thanks Nick. I've gone in a different direction today - AMCharts, which I have to say I'm really impressed with.

I'll be having a look at Fusion Charts though as well.

FourDegreez




msg:3932845
 2:30 am on Jun 14, 2009 (gmt 0)

While we're throwing out suggestions, I really like pChart.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved