Added multi bar chart. Added margin options.
This commit is contained in:
@@ -4,6 +4,7 @@ require_once './libraries/chart/pma_ofc_pie.php';
|
||||
|
||||
require_once './libraries/chart/pma_pchart_pie.php';
|
||||
require_once './libraries/chart/pma_pchart_single_bar.php';
|
||||
require_once './libraries/chart/pma_pchart_multi_bar.php';
|
||||
require_once './libraries/chart/pma_pchart_stacked_bar.php';
|
||||
require_once './libraries/chart/pma_pchart_single_line.php';
|
||||
require_once './libraries/chart/pma_pchart_multi_line.php';
|
||||
@@ -75,6 +76,11 @@ function PMA_chart_results($data, &$chartSettings)
|
||||
$chartSettings['type'] = 'bar';
|
||||
}
|
||||
|
||||
// set default bar type if needed
|
||||
if ($chartSettings['type'] == 'bar' && empty($chartSettings['barType'])) {
|
||||
$chartSettings['barType'] = 'stacked';
|
||||
}
|
||||
|
||||
if (!isset($data[0])) {
|
||||
// empty data
|
||||
return __('No data found for the chart.');
|
||||
@@ -92,8 +98,9 @@ function PMA_chart_results($data, &$chartSettings)
|
||||
}
|
||||
}
|
||||
|
||||
switch ($chartSettings['type'])
|
||||
{
|
||||
$chartSettings['multi'] = false;
|
||||
|
||||
switch ($chartSettings['type']) {
|
||||
case 'bar':
|
||||
default:
|
||||
$chart = new PMA_pChart_single_bar($chartTitle, $chartData, $chartSettings);
|
||||
@@ -140,12 +147,25 @@ function PMA_chart_results($data, &$chartSettings)
|
||||
}
|
||||
}
|
||||
|
||||
switch ($chartSettings['type'])
|
||||
{
|
||||
$chartSettings['multi'] = true;
|
||||
|
||||
// determine the chart type
|
||||
switch ($chartSettings['type']) {
|
||||
case 'bar':
|
||||
default:
|
||||
|
||||
// determine the bar chart type
|
||||
switch ($chartSettings['barType']) {
|
||||
case 'stacked':
|
||||
default:
|
||||
$chart = new PMA_pChart_stacked_bar($chartTitle, $chartData, $chartSettings);
|
||||
break;
|
||||
case 'multi':
|
||||
$chart = new PMA_pChart_multi_bar($chartTitle, $chartData, $chartSettings);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'line':
|
||||
$chart = new PMA_pChart_multi_line($chartTitle, $chartData, $chartSettings);
|
||||
break;
|
||||
|
@@ -37,7 +37,7 @@ abstract class PMA_pChart_Chart extends PMA_Chart
|
||||
$this->settings['labelHeight'] = 20;
|
||||
|
||||
// as in CSS (top, right, bottom, left)
|
||||
$this->settings['areaMargins'] = array(20, 20, 40, 60);
|
||||
$this->setAreaMargins(array(20, 20, 40, 60));
|
||||
|
||||
// create pChart object
|
||||
$this->chart = new pChart($this->getWidth(), $this->getHeight());
|
||||
@@ -138,6 +138,13 @@ abstract class PMA_pChart_Chart extends PMA_Chart
|
||||
return $this->settings['labelHeight'];
|
||||
}
|
||||
|
||||
protected function setAreaMargins($areaMargins)
|
||||
{
|
||||
if (!isset($this->settings['areaMargins'])) {
|
||||
$this->settings['areaMargins'] = $areaMargins;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getAreaMargin($side)
|
||||
{
|
||||
return $this->settings['areaMargins'][$side];
|
||||
|
@@ -13,7 +13,7 @@ abstract class PMA_pChart_multi extends PMA_pChart_chart
|
||||
parent::__construct($titleText, $data, $options);
|
||||
|
||||
// as in CSS (top, right, bottom, left)
|
||||
$this->settings['legendMargins'] = array(20, 10, 0, 0);
|
||||
$this->setLegendMargins(array(20, 10, 0, 0));
|
||||
}
|
||||
|
||||
protected function prepareDataSet()
|
||||
@@ -65,6 +65,13 @@ abstract class PMA_pChart_multi extends PMA_pChart_chart
|
||||
);
|
||||
}
|
||||
|
||||
protected function setLegendMargins($legendMargins)
|
||||
{
|
||||
if (!isset($this->settings['legendMargins'])) {
|
||||
$this->settings['legendMargins'] = $legendMargins;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getLegendMargin($side)
|
||||
{
|
||||
return $this->settings['legendMargins'][$side];
|
||||
|
23
libraries/chart/pma_pchart_multi_bar.php
Normal file
23
libraries/chart/pma_pchart_multi_bar.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
require_once 'pma_pchart_multi.php';
|
||||
|
||||
class PMA_pChart_multi_bar extends PMA_pChart_multi
|
||||
{
|
||||
public function __construct($titleText, $data, $options = null)
|
||||
{
|
||||
parent::__construct($titleText, $data, $options);
|
||||
|
||||
$this->settings['scale'] = SCALE_NORMAL;
|
||||
}
|
||||
|
||||
protected function drawChart()
|
||||
{
|
||||
parent::drawChart();
|
||||
|
||||
// Draw the bar chart
|
||||
$this->chart->drawBarGraph($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),70);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -98,12 +98,43 @@ $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>
|
||||
|
||||
<tr><td><label for="areaMargins"><?php echo __("Area margins"); ?></label></td>
|
||||
<td>
|
||||
<input type="text" name="chartSettings[areaMargins][]" size="2" value="<?php echo $chartSettings['areaMargins'][0]; ?>" />
|
||||
<input type="text" name="chartSettings[areaMargins][]" size="2" value="<?php echo $chartSettings['areaMargins'][1]; ?>" />
|
||||
<input type="text" name="chartSettings[areaMargins][]" size="2" value="<?php echo $chartSettings['areaMargins'][2]; ?>" />
|
||||
<input type="text" name="chartSettings[areaMargins][]" size="2" value="<?php echo $chartSettings['areaMargins'][3]; ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php if (isset($chartSettings['multi']) && $chartSettings['multi'] == 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]; ?>" />
|
||||
<input type="text" name="chartSettings[legendMargins][]" size="2" value="<?php echo $chartSettings['legendMargins'][1]; ?>" />
|
||||
<input type="text" name="chartSettings[legendMargins][]" size="2" value="<?php echo $chartSettings['legendMargins'][2]; ?>" />
|
||||
<input type="text" name="chartSettings[legendMargins][]" size="2" value="<?php echo $chartSettings['legendMargins'][3]; ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
|
||||
<tr><td><label for="type"><?php echo __("Type"); ?></label></td>
|
||||
<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
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php if ($chartSettings['type'] == 'bar' && isset($chartSettings['multi']) && $chartSettings['multi'] == true) { ?>
|
||||
<tr><td><label for="barType"><?php echo __("Bar type"); ?></label></td>
|
||||
<td>
|
||||
<input type="radio" name="chartSettings[barType]" value="stacked" <?php echo ($chartSettings['barType'] == 'stacked' ? 'checked' : ''); ?>>Stacked
|
||||
<input type="radio" name="chartSettings[barType]" value="multi" <?php echo ($chartSettings['barType'] == 'multi' ? 'checked' : ''); ?>>Multi
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
|
||||
</table>
|
||||
|
||||
</fieldset>
|
||||
|
Reference in New Issue
Block a user