added query results chart when results have only one column.

This commit is contained in:
Martynas Mickevicius
2010-07-27 12:52:46 +03:00
parent b7daf5d985
commit 3afe966b51
2 changed files with 23 additions and 9 deletions

View File

@@ -36,7 +36,7 @@ function PMA_chart_status($data)
} }
$chart = new PMA_pChart_Pie( $chart = new PMA_pChart_Pie(
array_slice($chartData, 0, 18, true), $chartData,
array('titleText' => __('Query statistics')) array('titleText' => __('Query statistics'))
); );
$chartCode = $chart->toString(); $chartCode = $chart->toString();
@@ -57,7 +57,7 @@ function PMA_chart_profiling($data)
} }
$chart = new PMA_pChart_Pie( $chart = new PMA_pChart_Pie(
array_slice($chartData, 0, 18, true), $chartData,
array('titleText' => __('Query execution time comparison (in microseconds)')) array('titleText' => __('Query execution time comparison (in microseconds)'))
); );
$chartCode = $chart->toString(); $chartCode = $chart->toString();
@@ -99,16 +99,22 @@ function PMA_chart_results($data, &$chartSettings, &$chartErrors = array())
return __('No data found for the chart.'); return __('No data found for the chart.');
} }
if (count($data[0]) == 2) { if (count($data[0]) == 1 || count($data[0] == 2)) {
// Two columns in every row. // Two columns in every row.
// This data is suitable for a simple bar chart. // This data is suitable for a simple bar chart.
if ($chartSettings['type'] == 'pie') { if ($chartSettings['type'] == 'pie') {
// loop through the rows, data for pie chart has to be formated // loop through the rows, data for pie chart has to be formated
// in a different way then in other charts. // in a different way then in other charts.
foreach ($data as $row) { foreach ($data as $rowKey => $row) {
$values = array_values($row); $values = array_values($row);
$chartData[$values[0]] = $values[1];
if (count($row) == 1) {
$chartData[$rowKey] = $values[0];
}
else {
$chartData[$values[0]] = $values[1];
}
} }
$chartSettings['legend'] = true; $chartSettings['legend'] = true;
@@ -116,10 +122,17 @@ function PMA_chart_results($data, &$chartSettings, &$chartErrors = array())
} }
else { else {
// loop through the rows // loop through the rows
foreach ($data as $row) { foreach ($data as $rowKey => $row) {
// if only one column, we need to add
// placeholder data for x axis
if (count($row) == 1) {
$chartData[''][] = $rowKey;
}
// loop through the columns in the row // loop through the columns in the row
foreach ($row as $key => $value) { foreach ($row as $valueKey => $value) {
$chartData[$key][] = $value; $chartData[$valueKey][] = $value;
} }
} }

View File

@@ -6,6 +6,7 @@ class PMA_pChart_Pie extends PMA_pChart_multi
{ {
public function __construct($data, $options = null) public function __construct($data, $options = null)
{ {
$data = array_slice($data, 0, 18, true);
parent::__construct($data, $options); parent::__construct($data, $options);
$this->setAreaMargins(array(20, 10, 20, 20)); $this->setAreaMargins(array(20, 10, 20, 20));