← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4522: Implemented stacked bar chart

 

Merge authors:
  Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 4522 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-09-05 23:57:06 +0200
message:
  Implemented stacked bar chart
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartForm.vm


--
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-api/src/main/java/org/hisp/dhis/chart/Chart.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java	2011-07-22 04:09:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/Chart.java	2011-09-05 17:12:10 +0000
@@ -65,6 +65,10 @@
 
     public static final String TYPE_BAR3D = "bar3d";
 
+    public static final String TYPE_STACKED_BAR = "stackedBar";
+    
+    public static final String TYPE_STACKED_BAR3D = "stackedBar3d";
+    
     public static final String TYPE_LINE = "line";
 
     public static final String TYPE_LINE3D = "line3d";
@@ -72,7 +76,7 @@
     public static final String TYPE_PIE = "pie";
 
     public static final String TYPE_PIE3D = "pie3d";
-
+    
     public static final String SIZE_NORMAL = "normal";
 
     public static final String SIZE_WIDE = "wide";

=== 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	2011-08-28 17:52:59 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2011-09-05 21:57:06 +0000
@@ -40,6 +40,8 @@
 import static org.hisp.dhis.chart.Chart.TYPE_LINE3D;
 import static org.hisp.dhis.chart.Chart.TYPE_PIE;
 import static org.hisp.dhis.chart.Chart.TYPE_PIE3D;
+import static org.hisp.dhis.chart.Chart.TYPE_STACKED_BAR;
+import static org.hisp.dhis.chart.Chart.TYPE_STACKED_BAR3D;
 import static org.hisp.dhis.options.SystemSettingManager.AGGREGATION_STRATEGY_REAL_TIME;
 import static org.hisp.dhis.options.SystemSettingManager.DEFAULT_AGGREGATION_STRATEGY;
 import static org.hisp.dhis.options.SystemSettingManager.KEY_AGGREGATION_STRATEGY;
@@ -602,48 +604,11 @@
         }
         else if ( chart.isType( TYPE_PIE ) || chart.isType( TYPE_PIE3D ) )
         {
-            JFreeChart multiplePieChart = null;
-
-            if ( chart.isType( TYPE_PIE ) )
-            {
-                multiplePieChart = ChartFactory.createMultiplePieChart( chart.getTitle(), dataSets[0],
-                    TableOrder.BY_ROW, !chart.getHideLegend(), false, false );
-            }
-            else
-            {
-                multiplePieChart = ChartFactory.createMultiplePieChart3D( chart.getTitle(), dataSets[0],
-                    TableOrder.BY_ROW, !chart.getHideLegend(), false, false );
-            }
-
-            multiplePieChart.setBackgroundPaint( Color.WHITE );
-            multiplePieChart.setAntiAlias( true );
-
-            TextTitle title = multiplePieChart.getTitle();
-            title.setFont( titleFont );
-
-            LegendTitle legend = multiplePieChart.getLegend();
-            legend.setItemFont( subTitleFont );
-
-            MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot();
-            JFreeChart pieChart = multiplePiePlot.getPieChart();
-            pieChart.getTitle().setFont( subTitleFont );
-
-            PiePlot piePlot = (PiePlot) pieChart.getPlot();
-            piePlot.setBackgroundPaint( Color.WHITE );
-            piePlot.setShadowXOffset( 0 );
-            piePlot.setShadowYOffset( 0 );
-            piePlot.setLabelFont( new Font( "Tahoma", Font.PLAIN, 10 ) );
-            piePlot.setLabelGenerator( new StandardPieSectionLabelGenerator( "{2}" ) );
-            piePlot.setSimpleLabels( true );
-            piePlot.setIgnoreZeroValues( true );
-            piePlot.setIgnoreNullValues( true );
-
-            for ( int i = 0; i < dataSets[0].getColumnCount(); i++ )
-            {
-                piePlot.setSectionPaint( dataSets[0].getColumnKey( i ), colors[(i % colors.length)] );
-            }
-
-            return multiplePieChart;
+            return getMultiplePieChart( chart, dataSets );
+        }
+        else if ( chart.isType( TYPE_STACKED_BAR ) || chart.isType( TYPE_STACKED_BAR3D ))
+        {
+            return getStackedBarChart( chart, dataSets[0] );
         }
 
         if ( chart.isRegression() )
@@ -697,6 +662,82 @@
         return jFreeChart;
     }
 
+    private JFreeChart getStackedBarChart( Chart chart, CategoryDataset dataSet )
+    {
+        PlotOrientation orientation = chart.isHorizontalPlotOrientation() ? PlotOrientation.HORIZONTAL
+            : PlotOrientation.VERTICAL;
+        
+        JFreeChart stackedBarChart = null;
+        
+        if ( chart.isType( TYPE_STACKED_BAR ) )
+        {
+            stackedBarChart = ChartFactory.createStackedBarChart( chart.getTitle(), 
+                null, null, dataSet, orientation, true, false, false );
+        }
+        else
+        {
+            stackedBarChart = ChartFactory.createStackedBarChart3D( chart.getTitle(), 
+                null, null, dataSet, orientation, true, false, false );
+        }
+        
+        CategoryPlot plot = (CategoryPlot) stackedBarChart.getPlot();
+        plot.setBackgroundPaint( Color.WHITE );
+
+        CategoryAxis xAxis = plot.getDomainAxis();
+        xAxis.setCategoryLabelPositions( chart.isVerticalLabels() ? CategoryLabelPositions.UP_45
+            : CategoryLabelPositions.STANDARD );
+
+        stackedBarChart.setAntiAlias( true );
+        
+        return stackedBarChart;
+    }
+    
+    private JFreeChart getMultiplePieChart( Chart chart, CategoryDataset[] dataSets )
+    {
+        JFreeChart multiplePieChart = null;
+
+        if ( chart.isType( TYPE_PIE ) )
+        {
+            multiplePieChart = ChartFactory.createMultiplePieChart( chart.getTitle(), dataSets[0],
+                TableOrder.BY_ROW, !chart.getHideLegend(), false, false );
+        }
+        else
+        {
+            multiplePieChart = ChartFactory.createMultiplePieChart3D( chart.getTitle(), dataSets[0],
+                TableOrder.BY_ROW, !chart.getHideLegend(), false, false );
+        }
+
+        multiplePieChart.setBackgroundPaint( Color.WHITE );
+        multiplePieChart.setAntiAlias( true );
+
+        TextTitle title = multiplePieChart.getTitle();
+        title.setFont( titleFont );
+
+        LegendTitle legend = multiplePieChart.getLegend();
+        legend.setItemFont( subTitleFont );
+
+        MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot();
+        JFreeChart pieChart = multiplePiePlot.getPieChart();
+        pieChart.getTitle().setFont( subTitleFont );
+
+        PiePlot piePlot = (PiePlot) pieChart.getPlot();
+        piePlot.setBackgroundPaint( Color.WHITE );
+        piePlot.setShadowXOffset( 0 );
+        piePlot.setShadowYOffset( 0 );
+        piePlot.setLabelFont( new Font( "Tahoma", Font.PLAIN, 10 ) );
+        piePlot.setLabelGenerator( new StandardPieSectionLabelGenerator( "{2}" ) );
+        piePlot.setSimpleLabels( true );
+        piePlot.setIgnoreZeroValues( true );
+        piePlot.setIgnoreNullValues( true );
+
+        for ( int i = 0; i < dataSets[0].getColumnCount(); i++ )
+        {
+            piePlot.setSectionPaint( dataSets[0].getColumnKey( i ), colors[(i % colors.length)] );
+        }
+
+        return multiplePieChart;
+    }
+    
     /**
      * Returns a DefaultCategoryDataSet based on aggregated data for the chart.
      */

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2011-07-22 07:14:57 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties	2011-09-05 17:12:10 +0000
@@ -379,4 +379,6 @@
 intro_chart_groups = Create, modify, view and delete chart groups. Groups are used for improved analysis.
 intro_report_groups = Create, modify, view and delete report groups. Groups are used for improved analysis.
 intro_report_table_groups = Create, modify, view and delete report table groups. Groups are used for improved analysis.
-confirm_delete = Are you sure you want to delete this object ?
\ No newline at end of file
+confirm_delete = Are you sure you want to delete this object ?
+stacked_bar_chart = Stacked bar chart
+stacked_bar3d_chart = Stacked 3D bar chart
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartForm.vm	2011-07-07 13:29:56 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addChartForm.vm	2011-09-05 17:12:10 +0000
@@ -73,6 +73,8 @@
     			<option value="line3d"#if ( $!chart.type == "line3d" ) selected#end>$i18n.getString( "line3d_chart" )</option>
     			<option value="pie"#if ( $!chart.type == "pie" ) selected#end>$i18n.getString( "pie_chart" )</option>
     			<option value="pie3d"#if ( $!chart.type == "pie3d" ) selected#end>$i18n.getString( "pie3d_chart" )</option>
+    			<option value="stackedBar"#if ( $!chart.type == "stackedBar" ) selected#end>$i18n.getString( "stacked_bar_chart" )</option>
+    			<option value="stackedBar3d"#if ( $!chart.type == "stackedBar3d" ) selected#end>$i18n.getString( "stacked_bar3d_chart" )</option>
 		    </select>
 	    </td>
     </tr>