added chart type PIE to the query results charts

This commit is contained in:
Martynas Mickevicius
2010-07-08 12:40:03 +03:00
parent 933238bcfb
commit dfe34ad8d4
3 changed files with 53 additions and 20 deletions

View File

@@ -81,6 +81,12 @@ function PMA_chart_results($data, &$chartSettings)
$chartSettings['barType'] = 'stacked';
}
// default for legend
$chartSettings['legend'] = false;
// default for muti series
$chartSettings['multi'] = false;
if (!isset($data[0])) {
// empty data
return __('No data found for the chart.');
@@ -90,6 +96,18 @@ function PMA_chart_results($data, &$chartSettings)
// Two columns in every row.
// 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
foreach ($data as $row) {
// loop through the columns in the row
@@ -98,8 +116,6 @@ function PMA_chart_results($data, &$chartSettings)
}
}
$chartSettings['multi'] = false;
switch ($chartSettings['type']) {
case 'bar':
default:
@@ -110,9 +126,12 @@ function PMA_chart_results($data, &$chartSettings)
break;
}
}
}
else if (count($data[0]) == 3) {
// Three columns (x axis, y axis, series) in every row.
// This data is suitable for a stacked bar chart.
$chartSettings['multi'] = true;
$keys = array_keys($data[0]);
$xAxisKey = $keys[0];
$yAxisKey = $keys[1];
@@ -147,7 +166,7 @@ function PMA_chart_results($data, &$chartSettings)
}
}
$chartSettings['multi'] = true;
$chartSettings['legend'] = true;
// determine the chart type
switch ($chartSettings['type']) {

View File

@@ -8,7 +8,7 @@ class PMA_pChart_Pie extends PMA_pChart_multi
{
parent::__construct($titleText, $data, $options);
$this->settings['areaMargins'] = array(20, 20, 20, 10);
$this->setAreaMargins(array(20, 20, 20, 10));
}
protected function prepareDataSet()
@@ -30,10 +30,19 @@ class PMA_pChart_Pie extends PMA_pChart_multi
{
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->dataSet->GetData(),
$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()

View File

@@ -91,6 +91,7 @@ $url_params['reload'] = 1;
<td><input type="text" name="chartSettings[title]" id="title" value="<?php echo $chartSettings['title']; ?>" /></td>
</tr>
<?php if ($chartSettings['type'] != 'pie') { ?>
<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>
</tr>
@@ -98,6 +99,7 @@ $url_params['reload'] = 1;
<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>
</tr>
<?php } ?>
<tr><td><label for="areaMargins"><?php echo __("Area margins"); ?></label></td>
<td>
@@ -108,7 +110,7 @@ $url_params['reload'] = 1;
</td>
</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>
<td>
<input type="text" name="chartSettings[legendMargins][]" size="2" value="<?php echo $chartSettings['legendMargins'][0]; ?>" />
@@ -123,6 +125,9 @@ $url_params['reload'] = 1;
<td>
<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
<?php if ($chartSettings['multi'] == false) { ?>
<input type="radio" name="chartSettings[type]" value="pie" <?php echo ($chartSettings['type'] == 'pie' ? 'checked' : ''); ?>>Pie
<?php } ?>
</td>
</tr>