← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3329: finished pie chart functionality

 

------------------------------------------------------------
revno: 3329
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2011-04-09 20:17:19 +0200
message:
  finished pie chart functionality
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	2011-04-09 17:21:45 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2011-04-09 18:17:19 +0000
@@ -80,6 +80,7 @@
 import org.jfree.chart.axis.CategoryAxis;
 import org.jfree.chart.axis.CategoryLabelPositions;
 import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
 import org.jfree.chart.plot.CategoryPlot;
 import org.jfree.chart.plot.DatasetRenderingOrder;
 import org.jfree.chart.plot.MultiplePiePlot;
@@ -88,6 +89,7 @@
 import org.jfree.chart.renderer.category.BarRenderer;
 import org.jfree.chart.renderer.category.CategoryItemRenderer;
 import org.jfree.chart.renderer.category.LineAndShapeRenderer;
+import org.jfree.chart.title.LegendTitle;
 import org.jfree.chart.title.TextTitle;
 import org.jfree.data.category.CategoryDataset;
 import org.jfree.data.category.DefaultCategoryDataset;
@@ -431,42 +433,43 @@
         {
             plot = new CategoryPlot( dataSets[0], new CategoryAxis(), new NumberAxis(), lineRenderer );
         }
-        else if ( chart.isType( TYPE_PIE ) )
+        else if ( chart.isType( TYPE_PIE ) || chart.isType( TYPE_PIE3D ) )
         {
-            JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart( chart.getTitle(), dataSets[0],
-                TableOrder.BY_ROW, !chart.getHideLegend(), false, false );
+            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 );
 
-            MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot();
-            PiePlot piePlot = (PiePlot) multiplePiePlot.getPieChart().getPlot();
-            piePlot.setBackgroundPaint( Color.WHITE );
-            piePlot.setShadowXOffset( 0 );
-            piePlot.setShadowYOffset( 0 );
-            piePlot.setLabelGenerator( null );
-
-            for ( int i = 0; i < dataSets[0].getColumnCount(); i++ )
-            {
-                piePlot.setSectionPaint( dataSets[0].getColumnKey( i ), colors[i] );
-            }
-
-            return multiplePieChart;
-        }
-        else if ( chart.isType( TYPE_PIE3D ) )
-        {
-            JFreeChart multiplePieChart = ChartFactory.createMultiplePieChart3D( chart.getTitle(), dataSets[0],
-                TableOrder.BY_ROW, !chart.getHideLegend(), false, false );
-            multiplePieChart.setBackgroundPaint( Color.WHITE );
-            multiplePieChart.setAntiAlias( true );
-
-            MultiplePiePlot multiplePiePlot = (MultiplePiePlot) multiplePieChart.getPlot();
-            PiePlot piePlot = (PiePlot) multiplePiePlot.getPieChart().getPlot();
-            piePlot.setBackgroundPaint( Color.WHITE );
-            piePlot.setShadowXOffset( 0 );
-            piePlot.setShadowYOffset( 0 );
+            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++ )
             {