early code to show a chart for query results

This commit is contained in:
Martynas Mickevicius
2010-06-21 17:35:42 +03:00
parent 9970ce91da
commit 12d875dadc
4 changed files with 160 additions and 1 deletions

View File

@@ -1,7 +1,9 @@
<?php
require_once './libraries/chart/pma_ofc_pie.php';
require_once './libraries/chart/pma_pChart_pie.php';
require_once './libraries/chart/pma_pChart_bar.php';
/**
* Chart functions used to generate various types
@@ -49,4 +51,26 @@ function PMA_chart_profiling($data)
echo $chart->toString();
}
/*
* Formats a chart for query results page.
*/
function PMA_chart_results($data)
{
$chartData = array();
// loop through the rows
foreach ($data as $row) {
// loop through the columns in the row
foreach ($row as $key => $value) {
$chartData[$key][] = $value;
}
}
$chart = new PMA_pChart_bar(
__('Query results'),
$chartData);
echo $chart->toString();
}
?>

View File

@@ -0,0 +1,53 @@
<?php
require_once 'pma_pchart_chart.php';
class PMA_pChart_bar extends PMA_pChart_Chart
{
private $labelHeight = 20;
// as in CSS (top, right, bottom, left)
private $areaMargins = array(20, 20, 40, 60);
protected function prepareDataSet()
{
$values = array_values($this->data);
$keys = array_keys($this->data);
// Dataset definition
$this->dataSet = new pData;
$this->dataSet->AddPoint($values[1], "Values");
$this->dataSet->AddPoint($values[0], "Keys");
$this->dataSet->AddAllSeries();
//$DataSet->RemoveSerie("Serie3");
$this->dataSet->SetAbsciseLabelSerie("Keys");
$this->dataSet->SetXAxisName($keys[0]);
$this->dataSet->SetYAxisName($keys[1]);
//$DataSet->SetYAxisUnit("°C");
//$DataSet->SetXAxisUnit("h");
}
protected function prepareChart()
{
// Initialise the graph
$this->chart = new pChart($this->width, $this->height);
$this->chart->drawGraphAreaGradient(132,173,131,50,TARGET_BACKGROUND);
$this->chart->setFontProperties($this->fontPath.'tahoma.ttf', 8);
$this->chart->setGraphArea($this->areaMargins[3],$this->labelHeight + $this->areaMargins[0],$this->width - $this->areaMargins[1],$this->height - $this->areaMargins[2]);
$this->chart->drawGraphArea(213,217,221,FALSE);
$this->chart->drawScale($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),SCALE_ADDALL,213,217,221,TRUE,0,2,TRUE);
$this->chart->drawGraphAreaGradient(163,203,167,50);
$this->chart->drawGrid(4,TRUE,230,230,230,20);
// Draw the bar chart
$this->chart->drawStackedBarGraph($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),70);
// Draw the title
$this->chart->drawTextBox(0,0,$this->width,$this->labelHeight,$titleText,0,255,255,255,ALIGN_CENTER,TRUE,0,0,0,30);
$this->chart->addBorder(2);
}
}
?>

View File

@@ -2228,7 +2228,7 @@ function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
// show chart
echo PMA_linkOrButton(
'tbl_chart.php' . PMA_generate_common_url($_url_params),
PMA_getIcon('b_chart.png', __('Show chart'), false, true),
PMA_getIcon('b_chart.png', __('Display chart'), false, true),
'', true, true, '') . "\n";
}

82
tbl_chart.php Normal file
View File

@@ -0,0 +1,82 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* handles creation of the chart
*
* @version $Id$
* @package phpMyAdmin
*/
/**
* do not import request variable into global scope
* @ignore
*/
if (! defined('PMA_NO_VARIABLES_IMPORT')) {
define('PMA_NO_VARIABLES_IMPORT', true);
}
/**
*
*/
require_once './libraries/common.inc.php';
/**
* Runs common work
*/
require './libraries/db_common.inc.php';
$url_params['goto'] = $cfg['DefaultTabDatabase'];
$url_params['back'] = 'view_create.php';
/*
* Import chart functions
*/
require_once './libraries/chart.lib.php';
/*
* Execute the query and return the result
*/
$data = array();
$result = PMA_DBI_try_query($sql_query);
while ($row = PMA_DBI_fetch_assoc($result)) {
$data[] = $row;
/*foreach ($row as $key => $value) {
$chartData[$key][] = $value;
}*/
}
/**
* Displays top menu links
* We use db links because a chart is not necessarily on a single table
*/
$num_tables = 0;
require_once './libraries/db_links.inc.php';
$url_params['db'] = $GLOBALS['db'];
$url_params['reload'] = 1;
/**
* Displays the page
*/
?>
<!-- CREATE VIEW options -->
<div id="div_view_options">
<form method="post" action="view_create.php">
<?php echo PMA_generate_common_hidden_inputs($url_params); ?>
<fieldset>
<legend><?php echo __('Display chart'); ?></legend>
<?php echo PMA_chart_results($data); ?>
</fieldset>
<fieldset class="tblFooters">
<input type="submit" name="displayChart" value="<?php echo __('Go'); ?>" />
</fieldset>
</form>
</div>
<?php
/**
* Displays the footer
*/
require_once './libraries/footer.inc.php';
?>