added chart type PIE to the query results charts
This commit is contained in:
@@ -81,6 +81,12 @@ function PMA_chart_results($data, &$chartSettings)
|
|||||||
$chartSettings['barType'] = 'stacked';
|
$chartSettings['barType'] = 'stacked';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// default for legend
|
||||||
|
$chartSettings['legend'] = false;
|
||||||
|
|
||||||
|
// default for muti series
|
||||||
|
$chartSettings['multi'] = false;
|
||||||
|
|
||||||
if (!isset($data[0])) {
|
if (!isset($data[0])) {
|
||||||
// empty data
|
// empty data
|
||||||
return __('No data found for the chart.');
|
return __('No data found for the chart.');
|
||||||
@@ -90,6 +96,18 @@ function PMA_chart_results($data, &$chartSettings)
|
|||||||
// 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') {
|
||||||
|
// loop through the rows, data for pie chart has to be formated
|
||||||
|
// in a different way then in other charts.
|
||||||
|
foreach ($data as $row) {
|
||||||
|
$values = array_values($row);
|
||||||
|
$chartData[$values[0]] = $values[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
$chartSettings['legend'] = true;
|
||||||
|
$chart = new PMA_pChart_pie($chartTitle, $chartData, $chartSettings);
|
||||||
|
}
|
||||||
|
else {
|
||||||
// loop through the rows
|
// loop through the rows
|
||||||
foreach ($data as $row) {
|
foreach ($data as $row) {
|
||||||
// loop through the columns in the row
|
// loop through the columns in the row
|
||||||
@@ -98,8 +116,6 @@ function PMA_chart_results($data, &$chartSettings)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$chartSettings['multi'] = false;
|
|
||||||
|
|
||||||
switch ($chartSettings['type']) {
|
switch ($chartSettings['type']) {
|
||||||
case 'bar':
|
case 'bar':
|
||||||
default:
|
default:
|
||||||
@@ -110,9 +126,12 @@ function PMA_chart_results($data, &$chartSettings)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (count($data[0]) == 3) {
|
else if (count($data[0]) == 3) {
|
||||||
// Three columns (x axis, y axis, series) in every row.
|
// Three columns (x axis, y axis, series) in every row.
|
||||||
// This data is suitable for a stacked bar chart.
|
// This data is suitable for a stacked bar chart.
|
||||||
|
$chartSettings['multi'] = true;
|
||||||
|
|
||||||
$keys = array_keys($data[0]);
|
$keys = array_keys($data[0]);
|
||||||
$xAxisKey = $keys[0];
|
$xAxisKey = $keys[0];
|
||||||
$yAxisKey = $keys[1];
|
$yAxisKey = $keys[1];
|
||||||
@@ -147,7 +166,7 @@ function PMA_chart_results($data, &$chartSettings)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$chartSettings['multi'] = true;
|
$chartSettings['legend'] = true;
|
||||||
|
|
||||||
// determine the chart type
|
// determine the chart type
|
||||||
switch ($chartSettings['type']) {
|
switch ($chartSettings['type']) {
|
||||||
|
@@ -8,7 +8,7 @@ class PMA_pChart_Pie extends PMA_pChart_multi
|
|||||||
{
|
{
|
||||||
parent::__construct($titleText, $data, $options);
|
parent::__construct($titleText, $data, $options);
|
||||||
|
|
||||||
$this->settings['areaMargins'] = array(20, 20, 20, 10);
|
$this->setAreaMargins(array(20, 20, 20, 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function prepareDataSet()
|
protected function prepareDataSet()
|
||||||
@@ -30,10 +30,19 @@ class PMA_pChart_Pie extends PMA_pChart_multi
|
|||||||
{
|
{
|
||||||
parent::drawChart();
|
parent::drawChart();
|
||||||
|
|
||||||
|
// draw pie chart in the middle of graph area
|
||||||
|
$middleX = ($this->chart->GArea_X1 + $this->chart->GArea_X2) / 2;
|
||||||
|
$middleY = ($this->chart->GArea_Y1 + $this->chart->GArea_Y2) / 2;
|
||||||
|
|
||||||
$this->chart->drawPieGraph(
|
$this->chart->drawPieGraph(
|
||||||
$this->dataSet->GetData(),
|
$this->dataSet->GetData(),
|
||||||
$this->dataSet->GetDataDescription(),
|
$this->dataSet->GetDataDescription(),
|
||||||
180,160,120,PIE_PERCENTAGE,FALSE,60,30,10,1);
|
$middleX,
|
||||||
|
// pie graph is skewed. Upper part is shorter than the
|
||||||
|
// lower part. This is why we set an offset to the
|
||||||
|
// Y middle coordiantes.
|
||||||
|
$middleY - 15,
|
||||||
|
120,PIE_PERCENTAGE,FALSE,60,30,10,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function drawLegend()
|
protected function drawLegend()
|
||||||
|
@@ -91,6 +91,7 @@ $url_params['reload'] = 1;
|
|||||||
<td><input type="text" name="chartSettings[title]" id="title" value="<?php echo $chartSettings['title']; ?>" /></td>
|
<td><input type="text" name="chartSettings[title]" id="title" value="<?php echo $chartSettings['title']; ?>" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<?php if ($chartSettings['type'] != 'pie') { ?>
|
||||||
<tr><td><label for="xLabel"><?php echo __("X Axis label"); ?></label></td>
|
<tr><td><label for="xLabel"><?php echo __("X Axis label"); ?></label></td>
|
||||||
<td><input type="text" name="chartSettings[xLabel]" id="xLabel" value="<?php echo $chartSettings['xLabel']; ?>" /></td>
|
<td><input type="text" name="chartSettings[xLabel]" id="xLabel" value="<?php echo $chartSettings['xLabel']; ?>" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -98,6 +99,7 @@ $url_params['reload'] = 1;
|
|||||||
<tr><td><label for="yLabel"><?php echo __("Y Axis label"); ?></label></td>
|
<tr><td><label for="yLabel"><?php echo __("Y Axis label"); ?></label></td>
|
||||||
<td><input type="text" name="chartSettings[yLabel]" id="yLabel" value="<?php echo $chartSettings['yLabel']; ?>" /></td>
|
<td><input type="text" name="chartSettings[yLabel]" id="yLabel" value="<?php echo $chartSettings['yLabel']; ?>" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
<tr><td><label for="areaMargins"><?php echo __("Area margins"); ?></label></td>
|
<tr><td><label for="areaMargins"><?php echo __("Area margins"); ?></label></td>
|
||||||
<td>
|
<td>
|
||||||
@@ -108,7 +110,7 @@ $url_params['reload'] = 1;
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<?php if (isset($chartSettings['multi']) && $chartSettings['multi'] == true) { ?>
|
<?php if ($chartSettings['legend'] == true) { ?>
|
||||||
<tr><td><label for="legendMargins"><?php echo __("Legend margins"); ?></label></td>
|
<tr><td><label for="legendMargins"><?php echo __("Legend margins"); ?></label></td>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="chartSettings[legendMargins][]" size="2" value="<?php echo $chartSettings['legendMargins'][0]; ?>" />
|
<input type="text" name="chartSettings[legendMargins][]" size="2" value="<?php echo $chartSettings['legendMargins'][0]; ?>" />
|
||||||
@@ -123,6 +125,9 @@ $url_params['reload'] = 1;
|
|||||||
<td>
|
<td>
|
||||||
<input type="radio" name="chartSettings[type]" value="bar" <?php echo ($chartSettings['type'] == 'bar' ? 'checked' : ''); ?>>Bar
|
<input type="radio" name="chartSettings[type]" value="bar" <?php echo ($chartSettings['type'] == 'bar' ? 'checked' : ''); ?>>Bar
|
||||||
<input type="radio" name="chartSettings[type]" value="line" <?php echo ($chartSettings['type'] == 'line' ? 'checked' : ''); ?>>Line
|
<input type="radio" name="chartSettings[type]" value="line" <?php echo ($chartSettings['type'] == 'line' ? 'checked' : ''); ?>>Line
|
||||||
|
<?php if ($chartSettings['multi'] == false) { ?>
|
||||||
|
<input type="radio" name="chartSettings[type]" value="pie" <?php echo ($chartSettings['type'] == 'pie' ? 'checked' : ''); ?>>Pie
|
||||||
|
<?php } ?>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user