charts with Googlechart api

A place for users and developers of the Xataface to discuss and receive support.

charts with Googlechart api

Postby Martin Pruss » Fri Jun 13, 2008 1:27 pm

Hi Steve
I am currently experimenting with a sort of basic reporting with charts. I already was successful with "timeplot" http://simile.mit.edu/ (and your help with the sql statement ), but it is not really handy.
So now i give Googlecharts a try. These Charts are simply embedded in an image Url. eg.

Code: Select all
<img src="http://chart.apis.google.com/chart?cht=lc&amp;chd=s:cEAELFJHHHKUju9uuXUccEAE&amp;chco=76A4FB&amp;chls=2.0,0.0,0.0&amp;chs=600x125&amp;chg=7,10,1,0&amp;chxt=x,y&amp;chxl=0:%7Cwoche1%7Cwoche2%7Cwoche3%7Cwoche4%7Cwoche5%7Cwoche6%7Cwoche7%7Cwoche8%7Cwoche9%7C1:%7C0km%7C50km%7C100km" alt="Line chart with 5 vertical and two horizontal pale gray, solid grid lines">


This should even work in PhpBB ;)

Some Clever folks already Ported this to a PHP Class, see: http://luddep.se/notebook/2008/04/charts_with_php_and_google_charts_api
after the Class is included you could simply create a chart like this
Code: Select all
<?php
/** Include class */
include( 'GoogChart.class.php' );

/** Create chart */
$chart = new GoogChart();

// Set timeline graph data
$dataTimeline = array(
      '2007' => array(
         'January' => 31.0,
         'February' => 31.2,
         'March' => 41.8,
         'April' => 52.9,
         'May' => 53.7,
         'June' => 54.0,
         'July' => 64.5,
         'August' => 64.9,
         'September' => 55.4,
         'Oktober' => 36.0,
         'November' => 66.3,
         'December' => 36.3,
         ),
      '2006' => array(
         'January' => 25.0,
         'February' => 24.5,
         'March' => 24.5,
         'April' => 22.9,
         'May' => 22.9,
         'June' => 25.5,
         'July' => 25.5,
         'August' => 24.9,
         'September' => 27.3,
         'Oktober' => 27.3,
         'November' => 29.9,
         'December' => 29.9,
         ),
      '2005' => array(
         'January' => 15.0,
         'February' => 14.5,
         'March' => 14.5,
         'April' => 12.9,
         'May' => 12.9,
         'June' => 15.5,
         'July' => 15.5,
         'August' => 14.9,
         'September' => 17.3,
         'Oktober' => 17.3,
         'November' => 19.9,
         'December' => 19.9,
         ),
   );

/* # Chart 3 # */
echo '<h2>Timeline</h2>';
$chart->setChartAttrs( array(
   'type' => 'sparkline',
   'title' => 'Trainingsentwicklung ',
   'data' => $dataTimeline,
   'size' => array( 800, 200 ),
   'color' => $color,
   'labelsXY' => true,
   'fill' => array( '#ffffff', '#ffffff' ),

   ));
// Print chart
echo $chart;
?>


I was wondering , if i included this class wthin a tables delegate class and outputting the above snippet to a block eg:

Code: Select all
function block__before_main_column(){
  rest of the above snippet , exept the data arrays     
echo $chart
        return true;
    }


this could be a dead easy way to do some chart art in dataface ;)

I think I could manage to get the data to an array like the one above with a SQL statement but would't it be much cooler to do this the dataface way
I mean when i am in a delegate class for a Table , isn't it possible to get to the data like :
Code: Select all
$record->val('time entry');

Now the Question:
How to get the data out of a table (based on user or owner) into an assoc array like the one above
Hope this makes sense
cheers Martin
Martin Pruss
 
Posts: 61
Joined: Tue Oct 23, 2007 2:22 pm
Location: Berlin

Postby shannah » Mon Jun 16, 2008 2:34 pm

Google charts are way cool! I have been thinking of creating a module to integrate them into Dataface for some time - but I think I'll wait to create a general reporting module first.

Getting the data from dataface into an associative array as you require shouldn't be too difficult, but it will depend on how the tables are set up.

Quite often when you are producing a chart you will be using aggregate data on your tables. This means that you will probably want to perform a custom SQL query to get this information (because the query will probably involve a number of aggregate functions (count(), avg(), sum(), etc..) and group by clauses).

So it's hard for me to comment to specifically on this unless I know what kinds of queries you're trying to do and the table structures on which those queries will operate.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: charts with Googlechart api

Postby ADobkin » Fri Aug 12, 2011 8:42 pm

Has anyone here done any work with this or with a similar chart/graph tool? I am interested in creating dynamic charts in my application based on SQL queries, and I would prefer not to reinvent the wheel if someone has already done something similar.

Thanks,
Alan
ADobkin
 
Posts: 195
Joined: Mon Oct 22, 2007 7:31 pm
Location: Atlanta, GA, USA

Re: charts with Googlechart api

Postby ADobkin » Fri Aug 12, 2011 9:35 pm

Here are a few other PHP-based chart projects that look interesting....

http://jpgraph.net

http://pchart.sourceforge.net/

http://www.fusioncharts.com/free/

How to create bar graph in PHP with dynamic scaling
http://www.qualitycodes.com/tutorial.php?articleid=20

Alan
ADobkin
 
Posts: 195
Joined: Mon Oct 22, 2007 7:31 pm
Location: Atlanta, GA, USA


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 22 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved