← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7101: Harmonized column/bar png and ext charts

 

------------------------------------------------------------
revno: 7101
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-05-30 11:39:11 +0200
message:
  Harmonized column/bar png and ext charts
modified:
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2012-05-30 09:16:49 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2012-05-30 09:39:11 +0000
@@ -491,18 +491,29 @@
         if ( chart.isType( TYPE_LINE ) || chart.isType( TYPE_AREA ) )
         {
             plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), lineRenderer );
-        }
-        else if ( chart.isType( TYPE_BAR ) || chart.isType( TYPE_COLUMN ) )
-        {
-            plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), barRenderer );
+            plot.setOrientation( PlotOrientation.VERTICAL );
+        }
+        else if ( chart.isType( TYPE_COLUMN ) )
+        {
+            plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), barRenderer );
+            plot.setOrientation( PlotOrientation.VERTICAL );
+        }
+        else if ( chart.isType( TYPE_BAR ) )
+        {
+            plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), barRenderer );
+            plot.setOrientation( PlotOrientation.HORIZONTAL );
         }
         else if ( chart.isType( TYPE_PIE ) )
         {
             return getMultiplePieChart( chart, dataSets );
         }
-        else if ( chart.isType( TYPE_STACKED_BAR ) || chart.isType( TYPE_STACKED_COLUMN ) )
-        {
-            return getStackedBarChart( chart, dataSets[0] );
+        else if ( chart.isType( TYPE_STACKED_COLUMN ) )
+        {
+            return getStackedBarChart( chart, dataSets[0], false );
+        }
+        else if ( chart.isType( TYPE_STACKED_BAR ) )
+        {
+            return getStackedBarChart( chart, dataSets[0], true );
         }
 
         if ( chart.isRegression() )
@@ -528,23 +539,18 @@
             jFreeChart.addSubtitle( getSubTitle( chart ) );
         }
 
-        // ---------------------------------------------------------------------
-        // Plot orientation
-        // ---------------------------------------------------------------------
-
-        plot.setOrientation( PlotOrientation.VERTICAL );
         plot.setDatasetRenderingOrder( DatasetRenderingOrder.FORWARD );
 
         // ---------------------------------------------------------------------
         // Category label positions
         // ---------------------------------------------------------------------
 
-        CategoryAxis xAxis = plot.getDomainAxis();
-        xAxis.setCategoryLabelPositions( CategoryLabelPositions.UP_45 );
-        xAxis.setLabel( chart.getDomainAxisLabel() );
+        CategoryAxis domainAxis = plot.getDomainAxis();
+        domainAxis.setCategoryLabelPositions( CategoryLabelPositions.UP_45 );
+        domainAxis.setLabel( chart.getDomainAxisLabel() );
 
-        ValueAxis yAxis = plot.getRangeAxis();
-        yAxis.setLabel( chart.getRangeAxisLabel() );
+        ValueAxis rangeAxis = plot.getRangeAxis();
+        rangeAxis.setLabel( chart.getRangeAxisLabel() );
 
         // ---------------------------------------------------------------------
         // Color & antialias
@@ -556,7 +562,7 @@
         return jFreeChart;
     }
     
-    private JFreeChart getStackedBarChart( Chart chart, CategoryDataset dataSet )
+    private JFreeChart getStackedBarChart( Chart chart, CategoryDataset dataSet, boolean horizontal )
     {
         JFreeChart stackedBarChart = null;
 
@@ -574,6 +580,7 @@
         CategoryPlot plot = (CategoryPlot) stackedBarChart.getPlot();
         plot.setBackgroundPaint( Color.WHITE );
         plot.setOutlinePaint( Color.WHITE );
+        plot.setOrientation( horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL );
 
         CategoryAxis xAxis = plot.getDomainAxis();
         xAxis.setCategoryLabelPositions( CategoryLabelPositions.UP_45 );