Forum Moderators: coopster
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.
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?