diff --git a/libraries/chart.lib.php b/libraries/chart.lib.php index e135a7193..b245b2a4a 100644 --- a/libraries/chart.lib.php +++ b/libraries/chart.lib.php @@ -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: - $chart = new PMA_pChart_stacked_bar($chartTitle, $chartData, $chartSettings); + + // 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; diff --git a/libraries/chart/pma_pchart_chart.php b/libraries/chart/pma_pchart_chart.php index 10c19c8dc..57f10fd69 100644 --- a/libraries/chart/pma_pchart_chart.php +++ b/libraries/chart/pma_pchart_chart.php @@ -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]; diff --git a/libraries/chart/pma_pchart_multi.php b/libraries/chart/pma_pchart_multi.php index 0be03bf38..b4f67db40 100644 --- a/libraries/chart/pma_pchart_multi.php +++ b/libraries/chart/pma_pchart_multi.php @@ -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]; diff --git a/libraries/chart/pma_pchart_multi_bar.php b/libraries/chart/pma_pchart_multi_bar.php new file mode 100644 index 000000000..194ba2cc7 --- /dev/null +++ b/libraries/chart/pma_pchart_multi_bar.php @@ -0,0 +1,23 @@ +settings['scale'] = SCALE_NORMAL; + } + + protected function drawChart() + { + parent::drawChart(); + + // Draw the bar chart + $this->chart->drawBarGraph($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),70); + } +} + +?> diff --git a/tbl_chart.php b/tbl_chart.php index 11f2d7340..dffd4fae0 100644 --- a/tbl_chart.php +++ b/tbl_chart.php @@ -98,12 +98,43 @@ $url_params['reload'] = 1;