PHP Classes

File: sample_post_and_query.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of Tom Schaefer  >  QGoogleVisualizationAPI 2009  >  sample_post_and_query.php  >  Download  
File: sample_post_and_query.php
Role: Example script
Content type: text/plain
Description: Data Source Requests > Using The Query Language
Class: QGoogleVisualizationAPI 2009
Generate charts with Google Visualization API
Author: By
Last change: better conditioning
Date: 6 years ago
Size: 2,752 bytes


Class file image Download

include_once 'Google.merge.v_1_0.php';

<title>Data Source Requests > Using The Query Language</title>
= array("AreaChart", "BarChart", "ColumnChart", "LineChart", "PieChart", "Table");
$_POST and array_key_exists("chartType", $_POST) and in_array($_POST["chartType"], $chartTypes)){
$chartType = $_POST["chartType"];
array_key_exists("qry", $_POST) and array_key_exists("useQuery", $_POST) and $_POST["useQuery"]=="on"){
$query = $_POST["qry"];
  } else {
$query = 'SELECT A,D WHERE D > 100 ORDER BY D';
} else {
$chartType = 'AreaChart';
$query = 'SELECT A,D WHERE D > 100 ORDER BY D';

$id = 'viz';
$url = '';

# new visualization using template default
$v = new Google_Visualization("Default");

# register package
$p = new Google_Package(array("packages"=>array($chartType), "language"=>"de_DE"));
$v->setPackage($p); // set package object to visualization

# setup chart
$chart = new Google_Chart($chartType, Google_Base::getElementById($id));
$options = new Google_Config($chartType);
$options->setProperty("width", 550);
$chart->draw("data", $options);

# init functions
$f1 = new Google_Function('drawVisualization');
$f2 = new Google_Function('handleQueryResponse', array('response'));

# setup query
$q = new Google_Data_Query($url);



# setup response
$qr = new Google_Data_QueryResponse();
$qr->asVar( $chart->getDataTable() )->getDataTable();





<body style="font-family: Arial;border: 0 none;">
    <h1>Data Source Requests > Using The Query Language</h1>
    <form method="post">
    <select name="chartType">
    <?php foreach($chartTypes as $name):?>
<?php if($chartType==$name):?>
<option value="<?php echo $name?>" selected="selected"><?php echo $name;?></option>
      <?php else:?>
<option value="<?php echo $name?>"><?php echo $name;?></option>
      <?php endif;?>
<?php endforeach;?>
<textarea name="qry"><?php echo $query?></textarea>
      <input type="checkbox" name="useQuery" <?php echo (array_key_exists("useQuery", $_POST) and $_POST["useQuery"]=="on"?'checked="checked"':"")?>/>
    <input type="submit" value="ask" />
    <div id="<?php echo $id;?>" style="border:2px solid #ccc; margin:0 30px 30px 0;height: 400px; width: 600px;float:left;overflow:auto"></div>